I would like to know if there is any way to improve the speed of the following program:
f := 1 - (2 M)/r; M = 1;
Va := f ((l (l + 1))/r^2 + ((1 - S^2) !(
*SubscriptBox[([PartialD]), (r)]f))/r);(Axial potential)
rmin := r /. Last[FindMaximum[{V, r > M}, r]]
V1 := f !(
*SubscriptBox[([PartialD]), (r)]V);
V2 := f !(
*SubscriptBox[([PartialD]), (r)]V1);
V3 := f !(
*SubscriptBox[([PartialD]), (r)]V2);
V4 := f !(
*SubscriptBox[([PartialD]), (r)]V3);
V5 := f !(
*SubscriptBox[([PartialD]), (r)]V4);
V6 := f !(
*SubscriptBox[([PartialD]), (r)]V5);
[CapitalGamma] :=
1/Sqrt[-2 V2] (1/8 (V4/V2) (1/4 + (n + 1/2)^2) -
1/288 (V3/V2)^2 (7 + 60 (n + 1/2)^2));
[CapitalOmega] :=
1/(-2 V2) (5/6912 (V3 /V2)^4 (77 + 188 (n + 1/2)^2) -
1/384 (((V3)^2 V4)/(V2)^3) (51 + 100 (n + 1/2)^2) +
1/2304 (V4/V2)^2 (67 + 68 (n + 1/2)^2) +
1/288 ((V3 V5)/(V2)^2) (19 + 28 (n + 1/2)^2) -
1/288 (V6/V2) (5 + 4 (n + 1/2)^2));
[Omega] := Sqrt[
V + [CapitalGamma] Sqrt[(-2 V2)] -
I (n + 1/2) (1 + [CapitalOmega]) Sqrt[(-2 V2)]];
(********Plots********)
V := Va;
S = 0;
Print[Style["Scalar perturbation", {Bold, Larger}], " Spin = ", S]
pp = 100;
l = 2; n = 0;
P1 = Plot[{Re[[Omega]] /. r -> rmin, -Im[[Omega]] /.
r -> rmin }, {M, 10^-3, 30}, AxesLabel -> {"M", "[Omega]"},
PlotStyle -> {{Line, Blue}, {Dashed, Blue}},
PlotLegends -> Placed[{"[ScriptL]=2"}, {0.7, 0.8}],
PlotRange -> {{0, 30}, {0, Automatic}}, MaxRecursion -> Infinity,
PlotPoints -> pp]; // AbsoluteTiming
l = 3; n = 0;
P2 = Plot[{Re[[Omega]] /. r -> rmin, -Im[[Omega]] /.
r -> rmin }, {M, 10^-3, 30}, AxesLabel -> {"M", "[Omega]"},
PlotStyle -> {{Line, Red}, {Dashed, Red}},
PlotLegends -> Placed[{"[ScriptL]=3"}, {0.7, 0.8}],
PlotRange -> {{0, 30}, {0, Automatic}}, MaxRecursion -> Infinity,
PlotPoints -> pp]; // AbsoluteTiming
l = 4; n = 0;
P3 = Plot[{Re[[Omega]] /. r -> rmin, -Im[[Omega]] /.
r -> rmin }, {M, 10^-3, 30}, AxesLabel -> {"M", "[Omega]"},
PlotStyle -> {{Line, Black}, {Dashed, Black}},
PlotLegends -> Placed[{"[ScriptL]=4"}, {0.7, 0.8}],
PlotRange -> {{0, 30}, {0, Automatic}}, MaxRecursion -> Infinity,
PlotPoints -> pp]; // AbsoluteTiming
Show[P1, P2, P3, Frame -> True, FrameLabel -> {"Mass", "Frequency"},
ImageSize -> Medium]
I have to make several analysis for even more complicated Vs, and several different plots. They are taking longer and longer and I have no idea how make this faster. Right now it is taking several minutes to run it.
D[V, r]for instance - as it becomes messy. After changing MaxRecursion to 15 (the max allowed) and making these other edits it takes 0.924229 seconds on my machine though the plot is just flat lines. – flinty Jul 03 '20 at 16:56MaxRecursonandPlotPointsmakes no difference to me visually, and of course it's much, much faster. (I don't see flat lines like flinty. I see curves.) – C. E. Jul 03 '20 at 17:00rmin := r /. Last[FindMaximum[{V, r > M}, r]]comes before the definition ofV, you should moveVup. – flinty Jul 03 '20 at 17:07MaxRecursionandPlotPointshoping that it would be more precise. – Edison Santos Jul 03 '20 at 17:55