I am trying to 3D plot the function ϕ[σ, λ]
, but Mathematica keeps refusing to plot for the reason that the output involves complex numbers, even though by definition the function should not give any complex output. Here is the code I am using. It's a bit messy so please let me know if there's questions.
f[x_] = Exp[-(x - 5)^2]
G1[b_, σ_, λ_] = 0
G2[b_, σ_, λ_] = (1/π) Sqrt[b/σ] EllipticK[Abs[(λ^2 - 4 (σ - b)^2)/(16 σ*b)]];
G3[b_, σ_, λ_] = (4/π)*((b)/(Sqrt[λ^2 - 4 (σ - b)^2])) EllipticK[Abs[(16 σ*b)/(λ^2 - 4 (σ - b)^2)]];
G[b_, σ_, λ_] = Piecewise[{{G1[b, σ, λ], λ <= 2 Abs[σ - b]}, {G2[b, σ, λ], 2 Abs[σ - b] < λ < 2 Abs[σ + b]}, {G3[b, λ, σ], λ >= Abs[σ + b]}}];
ϕ[σ_, λ_] = 2*NIntegrate[f[b] G[b, σ, λ], {b, 0, ∞}]
Plot3D[ϕ[σ, λ], {σ, 0, 3}, {λ, 0, 12}, PlotRange -> {-1, 3}]
Basically, I just want to get it to plot the function successfully, so please let me know if you see anything out of place, or a small detail that might be useful to mess around with.
ϕ
should probably be defined usingSetDelayed
(:=
) rather thanSet
(=
). But after that, there seem to be numerical issues with the integration. Have you worked those out yet? $\endgroup$σ = 0.1
andλ = 11.1
:N[G[23/5, 1/100, 111/10], 30] (* -0.459389664108971824295451307681 - 0.340789496534245725392527434380 I*)
$\endgroup$