In the following, I want to know b[1000]
,
but it is taking a very long time even for b[30]
.
Please help
a[0]=1.
a[n_]:=a[n - 1] + 1./ Sqrt[a[n - 1]];
b[n_] := (a[n])^3/n^2;
b[30]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIn the following, I want to know b[1000]
,
but it is taking a very long time even for b[30]
.
Please help
a[0]=1.
a[n_]:=a[n - 1] + 1./ Sqrt[a[n - 1]];
b[n_] := (a[n])^3/n^2;
b[30]
Use memoization:
a[0] = 1.;
a[n_] := a[n] = a[n - 1] + 1./ Sqrt[a[n - 1]]
b[n_] := (a[n])^3/n^2;
b[1000] //AbsoluteTiming
{0.052607, 2.2588}
b
it is in turn callinga
recursively. Try the simple change ofa[n_]:=a[n]=
this should run quite quickly even for large n. Though be warned that it will use up memory, since you are trading speed for storage here. See this for more details. reference.wolfram.com/language/tutorial/… $\endgroup$ – enano9314 Aug 27 '18 at 4:32