Taking a long time to produce output
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
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]
programming recursion sequence
add a comment |Â
up vote
3
down vote
favorite
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]
programming recursion sequence
Every time you callb
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/…
– enano9314
Aug 27 at 4:32
1
@enano9314, Thanks a lot for your help
– Sachin
Aug 27 at 4:37
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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]
programming recursion sequence
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]
programming recursion sequence
edited Aug 27 at 4:35


Carl Woll
56k272146
56k272146
asked Aug 27 at 4:24


Sachin
614
614
Every time you callb
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/…
– enano9314
Aug 27 at 4:32
1
@enano9314, Thanks a lot for your help
– Sachin
Aug 27 at 4:37
add a comment |Â
Every time you callb
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/…
– enano9314
Aug 27 at 4:32
1
@enano9314, Thanks a lot for your help
– Sachin
Aug 27 at 4:37
Every time you call
b
it is in turn calling a
recursively. Try the simple change of a[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/…– enano9314
Aug 27 at 4:32
Every time you call
b
it is in turn calling a
recursively. Try the simple change of a[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/…– enano9314
Aug 27 at 4:32
1
1
@enano9314, Thanks a lot for your help
– Sachin
Aug 27 at 4:37
@enano9314, Thanks a lot for your help
– Sachin
Aug 27 at 4:37
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
7
down vote
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
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
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
add a comment |Â
up vote
7
down vote
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
add a comment |Â
up vote
7
down vote
up vote
7
down vote
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
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
answered Aug 27 at 4:33


Carl Woll
56k272146
56k272146
add a comment |Â
add a comment |Â
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180712%2ftaking-a-long-time-to-produce-output%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Every time you call
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/…– enano9314
Aug 27 at 4:32
1
@enano9314, Thanks a lot for your help
– Sachin
Aug 27 at 4:37