Taking a long time to produce output

The name of the pictureThe name of the pictureThe name of the pictureClash 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]






share|improve this question






















  • 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




    @enano9314, Thanks a lot for your help
    – Sachin
    Aug 27 at 4:37














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]






share|improve this question






















  • 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




    @enano9314, Thanks a lot for your help
    – Sachin
    Aug 27 at 4:37












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]






share|improve this question














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]








share|improve this question













share|improve this question




share|improve this question








edited Aug 27 at 4:35









Carl Woll

56k272146




56k272146










asked Aug 27 at 4:24









Sachin

614




614











  • 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




    @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






  • 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










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







share|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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







    share|improve this answer
























      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







      share|improve this answer






















        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







        share|improve this answer












        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








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 27 at 4:33









        Carl Woll

        56k272146




        56k272146



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery