More accurate normalization

This commit is contained in:
Nuwan Yapa 2025-08-05 16:27:23 -04:00
parent 20fa595fa2
commit 12acf3297e
2 changed files with 18 additions and 1 deletions

View File

@ -1,2 +1,17 @@
const ħc = 197.33 # MeVfm const ħc = 197.33 # MeVfm
const r_reg = 1E-8 # fm # regulator for R const r_reg = 1E-8 # fm # regulator for R
"Integrate a uniformly discretized function f using Simpson's rule where h is the step size and coefficient is an optional scaling factor."
function simpsons_integrate(f::AbstractVector{Float64}, h::Float64; coefficient::Float64 = 1.0)
@assert length(f) % 2 == 1 "Number of mesh divisions must be even for Simpson's rule"
s = sum(enumerate(f)) do (i, fi)
if i == 1 || i == length(f)
return fi
elseif i % 2 == 0
return 4fi
else
return 2fi
end
end
return (h/3) * coefficient * s
end

View File

@ -89,7 +89,9 @@ function solveNucleonWf(κ, p::Bool, E, s::system; normalize=true, algo=Vern9())
wf = hcat(wf_left[:, 1:(end - 1)], wf_right) wf = hcat(wf_left[:, 1:(end - 1)], wf_right)
if normalize if normalize
wf ./= norm(wf) * sqrt(Δr(s)) # integration by Reimann sum g2_int = simpsons_integrate(wf[1, :] .^ 2, Δr(s))
f2_int = simpsons_integrate(wf[2, :] .^ 2, Δr(s))
wf ./= sqrt(g2_int + f2_int)
end end
return wf return wf