From ec4e21488c0e8f4cd4e3ea8e41da6b41c735aa22 Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 19 Jan 2023 21:07:08 -0600 Subject: [PATCH] compute max binding energy function --- Schrick-Noah_Project-1.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Schrick-Noah_Project-1.R b/Schrick-Noah_Project-1.R index 8e4daa6..12b8020 100644 --- a/Schrick-Noah_Project-1.R +++ b/Schrick-Noah_Project-1.R @@ -40,5 +40,18 @@ print(carbon_df, row.names=FALSE) print(carbon_df[which.max(carbon_df$"B/A"),], row.names=FALSE) ## Part D: find the value of A that gives the maximum binding energy +computeMaxBind <- function(Z, precision=NA){ + if (is.na(precision)){precision <- 4} + maxBind <- -Inf + A.maxBind <- -Inf + for (i in seq(Z, 3*Z)){ + bindE <- computeBindingEnergy(i, Z)/i + if (bindE > maxBind){ + maxBind <- bindE + A.maxBind <- i + } + } + return(c(paste("Energy: ", round(maxBind, precision), "MeV"), paste("Nucleons: ", A.maxBind))) +} ## Part E: for each Z use the A that maximizes E/A \ No newline at end of file