I have the following Mathematica code. I do get the output graphs, but it takes like 12 seconds, on my computer. Longer still if I increase the value of n1
.
Are there ways that can speed up the code?
Code1[A_, n1_] := Module[{E2},
h = 197.327053^2;
a = 0.65;
r0 = 1.285;
k0 = ((V02) 2 m/h)^0.5;
R0 = r0 A^0.333;
m = (A/(A + 1.00866 ))*931.49432;
V02 = 40.5 + 0.13 A;
z = a Sqrt[(2 m/h) (V02 - E2)];
b = a*Sqrt[(2 m/h) (E2)];
q1 = Sqrt[(V02 - E2)/E2];
phi444[E_] := (z R0/a ) -
Sum[ ArcTan[2 z/n] - 2 ArcTan[z/(n + b)], {n, 1.0, n1}];
t1 = Plot[{Tan[phi444[E2]], -q1}, {E2, 0, 45.0}];
Print[t1]]
Sum
inphi444
at each plot point, but this is unnecessary because it does not depend on the value ofE
. Instead, change the definition ofphi444
tophi444[E_] := (...) - Evaluate@Sum[...]
(you can even do away with the function and just make it a constant. $\endgroup$