Slow computation of recursive sequencesCan one identify the design patterns of Mathematica?What does the...

How safe is the 4% rule if the U.S. goes back to the mean?

First author doesn't want a co-author to read the whole paper

Is wiring laying alongside an attic access opening a code violation or safety concern?

What is the most REALISTIC cause of a worldwide catastrophe/apocalypse in the near future? (next ~100 years)

Can we not simply connect a battery to a RAM to prevent data loss during power cuts?

Do more Americans want the Bidens investigated than Trump impeached?

How do I get my boyfriend to remove pictures of his ex girlfriend hanging in his apartment?

How are Aircraft Noses Designed?

Why isn't Hagrid removed from Hogwarts sooner in Harry's would-be 7th year?

Idiom for a situation or event that makes one poor or even poorer?

How should I understand FPGA architecture?

Code Golf Measurer © 2019

Where does the upgrade to macOS Catalina move root "/" directory files?

Advisor asked for my entire slide presentation so she could give the presentation at an international conference

Should I avoid "big words" when writing to a younger audience?

Split telescope into two eyes

Which culture used no personal names?

Are there any spells that enhance ranged attacks like some melee attack spells do for melee attacks

I need an automatic way of making a lot of folders

Is there a historical explanation as to why the USA people are so litigious compared to France?

Why do adjectives come before nouns in English?

Justify of equation to better explanation

Mapping string into integers

Would preaching in a church be advantageous for becoming a lecturer?



Slow computation of recursive sequences


Can one identify the design patterns of Mathematica?What does the construct f[x_] := f[x] = … mean?Creating Recursive SequencesDefining a recursive integral sequenceTangled up in sequences and recurrence relationsEvaluate recursive funtion as a whole before computing a recursive stepMimic a procedural, recursive clustering algorithm for site percolation using functional programmingRecursive calculation is very slowImproving my method for solving iterative algebraic equations






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
.everyonelovesstackoverflow{position:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;}








1














$begingroup$


I want to investigate the asymptotic behavior of the following recursive system:



a[n_] := (a[n-1] - 0.45 a[n-1]) + 0.3 b[n-1]
b[n_] := (b[n-1] - 0.3 b[n-1]) + 0.45 a[n-1]
a[0] = 450;
b[0] = 450;

Grid[Table[{n, a[n], b[n]}, {n, 0, 12}]]


It is working, however it is very slow. It seems that it doesn't memorize the calculated value, so it repeats the computation from the beginning.
Is there a way to make this computations faster?










share|improve this question









New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$
















  • $begingroup$
    Hi David. Please get into the habit of posting code directly in copyable form (with the appropriate markup). Towards your question: You probably want to learn about memoization, i.e. the art of defining Functions That Remember Values They Have Found.
    $endgroup$
    – Henrik Schumacher
    8 hours ago












  • $begingroup$
    @HenrikSchumacher Hi Henrik, I am sorry I first typed it as a copiable code, but I get the persisting error: "your post appears to contain code that is not properly formatted as code". That's why I inserted it as a picture.
    $endgroup$
    – David Lingard
    8 hours ago












  • $begingroup$
    related: Basic/Advanced Memoization, What does the construct f(x_) := f(x) = … mean?
    $endgroup$
    – WReach
    8 hours ago




















1














$begingroup$


I want to investigate the asymptotic behavior of the following recursive system:



a[n_] := (a[n-1] - 0.45 a[n-1]) + 0.3 b[n-1]
b[n_] := (b[n-1] - 0.3 b[n-1]) + 0.45 a[n-1]
a[0] = 450;
b[0] = 450;

Grid[Table[{n, a[n], b[n]}, {n, 0, 12}]]


It is working, however it is very slow. It seems that it doesn't memorize the calculated value, so it repeats the computation from the beginning.
Is there a way to make this computations faster?










share|improve this question









New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$
















  • $begingroup$
    Hi David. Please get into the habit of posting code directly in copyable form (with the appropriate markup). Towards your question: You probably want to learn about memoization, i.e. the art of defining Functions That Remember Values They Have Found.
    $endgroup$
    – Henrik Schumacher
    8 hours ago












  • $begingroup$
    @HenrikSchumacher Hi Henrik, I am sorry I first typed it as a copiable code, but I get the persisting error: "your post appears to contain code that is not properly formatted as code". That's why I inserted it as a picture.
    $endgroup$
    – David Lingard
    8 hours ago












  • $begingroup$
    related: Basic/Advanced Memoization, What does the construct f(x_) := f(x) = … mean?
    $endgroup$
    – WReach
    8 hours ago
















1












1








1





$begingroup$


I want to investigate the asymptotic behavior of the following recursive system:



a[n_] := (a[n-1] - 0.45 a[n-1]) + 0.3 b[n-1]
b[n_] := (b[n-1] - 0.3 b[n-1]) + 0.45 a[n-1]
a[0] = 450;
b[0] = 450;

Grid[Table[{n, a[n], b[n]}, {n, 0, 12}]]


It is working, however it is very slow. It seems that it doesn't memorize the calculated value, so it repeats the computation from the beginning.
Is there a way to make this computations faster?










share|improve this question









New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$




I want to investigate the asymptotic behavior of the following recursive system:



a[n_] := (a[n-1] - 0.45 a[n-1]) + 0.3 b[n-1]
b[n_] := (b[n-1] - 0.3 b[n-1]) + 0.45 a[n-1]
a[0] = 450;
b[0] = 450;

Grid[Table[{n, a[n], b[n]}, {n, 0, 12}]]


It is working, however it is very slow. It seems that it doesn't memorize the calculated value, so it repeats the computation from the beginning.
Is there a way to make this computations faster?







recursion difference-equations sequence markov-chains






share|improve this question









New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question



share|improve this question








edited 8 hours ago









WReach

55.7k2 gold badges122 silver badges222 bronze badges




55.7k2 gold badges122 silver badges222 bronze badges






New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 9 hours ago









David LingardDavid Lingard

82 bronze badges




82 bronze badges




New contributor



David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




David Lingard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

















  • $begingroup$
    Hi David. Please get into the habit of posting code directly in copyable form (with the appropriate markup). Towards your question: You probably want to learn about memoization, i.e. the art of defining Functions That Remember Values They Have Found.
    $endgroup$
    – Henrik Schumacher
    8 hours ago












  • $begingroup$
    @HenrikSchumacher Hi Henrik, I am sorry I first typed it as a copiable code, but I get the persisting error: "your post appears to contain code that is not properly formatted as code". That's why I inserted it as a picture.
    $endgroup$
    – David Lingard
    8 hours ago












  • $begingroup$
    related: Basic/Advanced Memoization, What does the construct f(x_) := f(x) = … mean?
    $endgroup$
    – WReach
    8 hours ago




















  • $begingroup$
    Hi David. Please get into the habit of posting code directly in copyable form (with the appropriate markup). Towards your question: You probably want to learn about memoization, i.e. the art of defining Functions That Remember Values They Have Found.
    $endgroup$
    – Henrik Schumacher
    8 hours ago












  • $begingroup$
    @HenrikSchumacher Hi Henrik, I am sorry I first typed it as a copiable code, but I get the persisting error: "your post appears to contain code that is not properly formatted as code". That's why I inserted it as a picture.
    $endgroup$
    – David Lingard
    8 hours ago












  • $begingroup$
    related: Basic/Advanced Memoization, What does the construct f(x_) := f(x) = … mean?
    $endgroup$
    – WReach
    8 hours ago


















$begingroup$
Hi David. Please get into the habit of posting code directly in copyable form (with the appropriate markup). Towards your question: You probably want to learn about memoization, i.e. the art of defining Functions That Remember Values They Have Found.
$endgroup$
– Henrik Schumacher
8 hours ago






$begingroup$
Hi David. Please get into the habit of posting code directly in copyable form (with the appropriate markup). Towards your question: You probably want to learn about memoization, i.e. the art of defining Functions That Remember Values They Have Found.
$endgroup$
– Henrik Schumacher
8 hours ago














$begingroup$
@HenrikSchumacher Hi Henrik, I am sorry I first typed it as a copiable code, but I get the persisting error: "your post appears to contain code that is not properly formatted as code". That's why I inserted it as a picture.
$endgroup$
– David Lingard
8 hours ago






$begingroup$
@HenrikSchumacher Hi Henrik, I am sorry I first typed it as a copiable code, but I get the persisting error: "your post appears to contain code that is not properly formatted as code". That's why I inserted it as a picture.
$endgroup$
– David Lingard
8 hours ago














$begingroup$
related: Basic/Advanced Memoization, What does the construct f(x_) := f(x) = … mean?
$endgroup$
– WReach
8 hours ago






$begingroup$
related: Basic/Advanced Memoization, What does the construct f(x_) := f(x) = … mean?
$endgroup$
– WReach
8 hours ago












3 Answers
3






active

oldest

votes


















2
















$begingroup$

These are all equivalent



RecurrenceTable[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1], 
b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
b[0] == 450}, {a[n], b[n]}, {n, 10}]

Clear[a, b]
{a[n], b[n]} /. RSolve[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1],
b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
b[0] == 450}, {a[n], b[n]}, n];
Table[%, {n, 0, 10}]

Clear[a, b]
a[n_] := a[n] = a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1]
b[n_] := b[n] = b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1]
a[0] = 450;
b[0] = 450;
Table[{a[n], b[n]}, {n, 0, 10}]



(* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
539.978}, {360.005, 539.995}, {360.001, 539.999}, {360.,
540.}, {360., 540.}}*)







share|improve this answer










$endgroup$























    2
















    $begingroup$

    The system can be solved in closed-form using RSolve



    Clear["Global`*"]

    eqns = {a[n] == (a[n - 1] - 0.45 a[n - 1]) + 0.3 b[n - 1],
    b[n] == (b[n - 1] - 0.3 b[n - 1]) + 0.45 a[n - 1],
    a[0] == 450, b[0] == 450} // Rationalize;

    sol = RSolve[eqns, {a, b}, n][[1]]

    (* {a -> Function[{n}, 45 2^(1 - 2 n) (1 + 2^(2 + 2 n))],
    b -> Function[{n}, 45 2^(1 - 2 n) (-1 + 3 2^(1 + 2 n))]} *)


    Verifying that the solutions satisfy the equations



    And @@ (eqns /. sol // Simplify)

    (* True *)


    The functions asymptotically approach



    Limit[{a[n], b[n]} /. sol, n -> Infinity]

    (* {360, 540} *)

    N[{a[#], b[#]} /. sol] & /@ Range [0, 10]

    (* {{450., 450.}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
    538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
    539.978}, {360.005, 539.995}, {360.001, 539.999}, {360., 540.}, {360.,
    540.}} *)

    Plot[Evaluate[{b[n], a[n]} /. sol], {n, 0, 15},
    PlotLegends -> Placed[{b[n], a[n]}, {0.5, 0.5}]]


    enter image description here



    Alternatively, using FixedPointList



    FixedPointList[
    {(#[[1]] - 0.45 #[[1]]) + 0.3 #[[2]],
    (#[[2]] - 0.3 #[[2]]) + 0.45 #[[1]]} &,
    {450, 450}]

    (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406, 538.594}, {360.352,
    539.648}, {360.088, 539.912}, {360.022, 539.978}, {360.005,
    539.995}, {360.001, 539.999}, {360., 540.}, {360., 540.}, {360.,
    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}} *)





    share|improve this answer










    $endgroup$























      1
















      $begingroup$

      The basic idea is



      a[n_]:=(a[n]=(a[n-1)0...)


      This will set downvalues for a, for each n to prevent re-computation






      share|improve this answer










      $endgroup$

















        Your Answer








        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',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });







        David Lingard is a new contributor. Be nice, and check out our Code of Conduct.










        draft saved

        draft discarded
















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f207540%2fslow-computation-of-recursive-sequences%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown


























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2
















        $begingroup$

        These are all equivalent



        RecurrenceTable[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1], 
        b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
        b[0] == 450}, {a[n], b[n]}, {n, 10}]

        Clear[a, b]
        {a[n], b[n]} /. RSolve[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1],
        b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
        b[0] == 450}, {a[n], b[n]}, n];
        Table[%, {n, 0, 10}]

        Clear[a, b]
        a[n_] := a[n] = a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1]
        b[n_] := b[n] = b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1]
        a[0] = 450;
        b[0] = 450;
        Table[{a[n], b[n]}, {n, 0, 10}]



        (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
        538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
        539.978}, {360.005, 539.995}, {360.001, 539.999}, {360.,
        540.}, {360., 540.}}*)







        share|improve this answer










        $endgroup$




















          2
















          $begingroup$

          These are all equivalent



          RecurrenceTable[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1], 
          b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
          b[0] == 450}, {a[n], b[n]}, {n, 10}]

          Clear[a, b]
          {a[n], b[n]} /. RSolve[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1],
          b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
          b[0] == 450}, {a[n], b[n]}, n];
          Table[%, {n, 0, 10}]

          Clear[a, b]
          a[n_] := a[n] = a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1]
          b[n_] := b[n] = b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1]
          a[0] = 450;
          b[0] = 450;
          Table[{a[n], b[n]}, {n, 0, 10}]



          (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
          538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
          539.978}, {360.005, 539.995}, {360.001, 539.999}, {360.,
          540.}, {360., 540.}}*)







          share|improve this answer










          $endgroup$


















            2














            2










            2







            $begingroup$

            These are all equivalent



            RecurrenceTable[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1], 
            b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
            b[0] == 450}, {a[n], b[n]}, {n, 10}]

            Clear[a, b]
            {a[n], b[n]} /. RSolve[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1],
            b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
            b[0] == 450}, {a[n], b[n]}, n];
            Table[%, {n, 0, 10}]

            Clear[a, b]
            a[n_] := a[n] = a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1]
            b[n_] := b[n] = b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1]
            a[0] = 450;
            b[0] = 450;
            Table[{a[n], b[n]}, {n, 0, 10}]



            (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
            538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
            539.978}, {360.005, 539.995}, {360.001, 539.999}, {360.,
            540.}, {360., 540.}}*)







            share|improve this answer










            $endgroup$



            These are all equivalent



            RecurrenceTable[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1], 
            b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
            b[0] == 450}, {a[n], b[n]}, {n, 10}]

            Clear[a, b]
            {a[n], b[n]} /. RSolve[{a[n] == a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1],
            b[n] == b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1], a[0] == 450,
            b[0] == 450}, {a[n], b[n]}, n];
            Table[%, {n, 0, 10}]

            Clear[a, b]
            a[n_] := a[n] = a[n - 1] - 0.45 a[n - 1] + 0.3 b[n - 1]
            b[n_] := b[n] = b[n - 1] - 0.3 b[n - 1] + 0.45 a[n - 1]
            a[0] = 450;
            b[0] = 450;
            Table[{a[n], b[n]}, {n, 0, 10}]



            (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
            538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
            539.978}, {360.005, 539.995}, {360.001, 539.999}, {360.,
            540.}, {360., 540.}}*)








            share|improve this answer













            share|improve this answer




            share|improve this answer



            share|improve this answer










            answered 8 hours ago









            Suba ThomasSuba Thomas

            4,28411 silver badges20 bronze badges




            4,28411 silver badges20 bronze badges




























                2
















                $begingroup$

                The system can be solved in closed-form using RSolve



                Clear["Global`*"]

                eqns = {a[n] == (a[n - 1] - 0.45 a[n - 1]) + 0.3 b[n - 1],
                b[n] == (b[n - 1] - 0.3 b[n - 1]) + 0.45 a[n - 1],
                a[0] == 450, b[0] == 450} // Rationalize;

                sol = RSolve[eqns, {a, b}, n][[1]]

                (* {a -> Function[{n}, 45 2^(1 - 2 n) (1 + 2^(2 + 2 n))],
                b -> Function[{n}, 45 2^(1 - 2 n) (-1 + 3 2^(1 + 2 n))]} *)


                Verifying that the solutions satisfy the equations



                And @@ (eqns /. sol // Simplify)

                (* True *)


                The functions asymptotically approach



                Limit[{a[n], b[n]} /. sol, n -> Infinity]

                (* {360, 540} *)

                N[{a[#], b[#]} /. sol] & /@ Range [0, 10]

                (* {{450., 450.}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
                538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
                539.978}, {360.005, 539.995}, {360.001, 539.999}, {360., 540.}, {360.,
                540.}} *)

                Plot[Evaluate[{b[n], a[n]} /. sol], {n, 0, 15},
                PlotLegends -> Placed[{b[n], a[n]}, {0.5, 0.5}]]


                enter image description here



                Alternatively, using FixedPointList



                FixedPointList[
                {(#[[1]] - 0.45 #[[1]]) + 0.3 #[[2]],
                (#[[2]] - 0.3 #[[2]]) + 0.45 #[[1]]} &,
                {450, 450}]

                (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406, 538.594}, {360.352,
                539.648}, {360.088, 539.912}, {360.022, 539.978}, {360.005,
                539.995}, {360.001, 539.999}, {360., 540.}, {360., 540.}, {360.,
                540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}} *)





                share|improve this answer










                $endgroup$




















                  2
















                  $begingroup$

                  The system can be solved in closed-form using RSolve



                  Clear["Global`*"]

                  eqns = {a[n] == (a[n - 1] - 0.45 a[n - 1]) + 0.3 b[n - 1],
                  b[n] == (b[n - 1] - 0.3 b[n - 1]) + 0.45 a[n - 1],
                  a[0] == 450, b[0] == 450} // Rationalize;

                  sol = RSolve[eqns, {a, b}, n][[1]]

                  (* {a -> Function[{n}, 45 2^(1 - 2 n) (1 + 2^(2 + 2 n))],
                  b -> Function[{n}, 45 2^(1 - 2 n) (-1 + 3 2^(1 + 2 n))]} *)


                  Verifying that the solutions satisfy the equations



                  And @@ (eqns /. sol // Simplify)

                  (* True *)


                  The functions asymptotically approach



                  Limit[{a[n], b[n]} /. sol, n -> Infinity]

                  (* {360, 540} *)

                  N[{a[#], b[#]} /. sol] & /@ Range [0, 10]

                  (* {{450., 450.}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
                  538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
                  539.978}, {360.005, 539.995}, {360.001, 539.999}, {360., 540.}, {360.,
                  540.}} *)

                  Plot[Evaluate[{b[n], a[n]} /. sol], {n, 0, 15},
                  PlotLegends -> Placed[{b[n], a[n]}, {0.5, 0.5}]]


                  enter image description here



                  Alternatively, using FixedPointList



                  FixedPointList[
                  {(#[[1]] - 0.45 #[[1]]) + 0.3 #[[2]],
                  (#[[2]] - 0.3 #[[2]]) + 0.45 #[[1]]} &,
                  {450, 450}]

                  (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406, 538.594}, {360.352,
                  539.648}, {360.088, 539.912}, {360.022, 539.978}, {360.005,
                  539.995}, {360.001, 539.999}, {360., 540.}, {360., 540.}, {360.,
                  540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                  540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                  540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}} *)





                  share|improve this answer










                  $endgroup$


















                    2














                    2










                    2







                    $begingroup$

                    The system can be solved in closed-form using RSolve



                    Clear["Global`*"]

                    eqns = {a[n] == (a[n - 1] - 0.45 a[n - 1]) + 0.3 b[n - 1],
                    b[n] == (b[n - 1] - 0.3 b[n - 1]) + 0.45 a[n - 1],
                    a[0] == 450, b[0] == 450} // Rationalize;

                    sol = RSolve[eqns, {a, b}, n][[1]]

                    (* {a -> Function[{n}, 45 2^(1 - 2 n) (1 + 2^(2 + 2 n))],
                    b -> Function[{n}, 45 2^(1 - 2 n) (-1 + 3 2^(1 + 2 n))]} *)


                    Verifying that the solutions satisfy the equations



                    And @@ (eqns /. sol // Simplify)

                    (* True *)


                    The functions asymptotically approach



                    Limit[{a[n], b[n]} /. sol, n -> Infinity]

                    (* {360, 540} *)

                    N[{a[#], b[#]} /. sol] & /@ Range [0, 10]

                    (* {{450., 450.}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
                    538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
                    539.978}, {360.005, 539.995}, {360.001, 539.999}, {360., 540.}, {360.,
                    540.}} *)

                    Plot[Evaluate[{b[n], a[n]} /. sol], {n, 0, 15},
                    PlotLegends -> Placed[{b[n], a[n]}, {0.5, 0.5}]]


                    enter image description here



                    Alternatively, using FixedPointList



                    FixedPointList[
                    {(#[[1]] - 0.45 #[[1]]) + 0.3 #[[2]],
                    (#[[2]] - 0.3 #[[2]]) + 0.45 #[[1]]} &,
                    {450, 450}]

                    (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406, 538.594}, {360.352,
                    539.648}, {360.088, 539.912}, {360.022, 539.978}, {360.005,
                    539.995}, {360.001, 539.999}, {360., 540.}, {360., 540.}, {360.,
                    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}} *)





                    share|improve this answer










                    $endgroup$



                    The system can be solved in closed-form using RSolve



                    Clear["Global`*"]

                    eqns = {a[n] == (a[n - 1] - 0.45 a[n - 1]) + 0.3 b[n - 1],
                    b[n] == (b[n - 1] - 0.3 b[n - 1]) + 0.45 a[n - 1],
                    a[0] == 450, b[0] == 450} // Rationalize;

                    sol = RSolve[eqns, {a, b}, n][[1]]

                    (* {a -> Function[{n}, 45 2^(1 - 2 n) (1 + 2^(2 + 2 n))],
                    b -> Function[{n}, 45 2^(1 - 2 n) (-1 + 3 2^(1 + 2 n))]} *)


                    Verifying that the solutions satisfy the equations



                    And @@ (eqns /. sol // Simplify)

                    (* True *)


                    The functions asymptotically approach



                    Limit[{a[n], b[n]} /. sol, n -> Infinity]

                    (* {360, 540} *)

                    N[{a[#], b[#]} /. sol] & /@ Range [0, 10]

                    (* {{450., 450.}, {382.5, 517.5}, {365.625, 534.375}, {361.406,
                    538.594}, {360.352, 539.648}, {360.088, 539.912}, {360.022,
                    539.978}, {360.005, 539.995}, {360.001, 539.999}, {360., 540.}, {360.,
                    540.}} *)

                    Plot[Evaluate[{b[n], a[n]} /. sol], {n, 0, 15},
                    PlotLegends -> Placed[{b[n], a[n]}, {0.5, 0.5}]]


                    enter image description here



                    Alternatively, using FixedPointList



                    FixedPointList[
                    {(#[[1]] - 0.45 #[[1]]) + 0.3 #[[2]],
                    (#[[2]] - 0.3 #[[2]]) + 0.45 #[[1]]} &,
                    {450, 450}]

                    (* {{450, 450}, {382.5, 517.5}, {365.625, 534.375}, {361.406, 538.594}, {360.352,
                    539.648}, {360.088, 539.912}, {360.022, 539.978}, {360.005,
                    539.995}, {360.001, 539.999}, {360., 540.}, {360., 540.}, {360.,
                    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360.,
                    540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}, {360., 540.}} *)






                    share|improve this answer













                    share|improve this answer




                    share|improve this answer



                    share|improve this answer










                    answered 6 hours ago









                    Bob HanlonBob Hanlon

                    66.4k3 gold badges37 silver badges102 bronze badges




                    66.4k3 gold badges37 silver badges102 bronze badges


























                        1
















                        $begingroup$

                        The basic idea is



                        a[n_]:=(a[n]=(a[n-1)0...)


                        This will set downvalues for a, for each n to prevent re-computation






                        share|improve this answer










                        $endgroup$




















                          1
















                          $begingroup$

                          The basic idea is



                          a[n_]:=(a[n]=(a[n-1)0...)


                          This will set downvalues for a, for each n to prevent re-computation






                          share|improve this answer










                          $endgroup$


















                            1














                            1










                            1







                            $begingroup$

                            The basic idea is



                            a[n_]:=(a[n]=(a[n-1)0...)


                            This will set downvalues for a, for each n to prevent re-computation






                            share|improve this answer










                            $endgroup$



                            The basic idea is



                            a[n_]:=(a[n]=(a[n-1)0...)


                            This will set downvalues for a, for each n to prevent re-computation







                            share|improve this answer













                            share|improve this answer




                            share|improve this answer



                            share|improve this answer










                            answered 8 hours ago









                            John McGeeJohn McGee

                            1,8387 silver badges13 bronze badges




                            1,8387 silver badges13 bronze badges


























                                David Lingard is a new contributor. Be nice, and check out our Code of Conduct.










                                draft saved

                                draft discarded

















                                David Lingard is a new contributor. Be nice, and check out our Code of Conduct.













                                David Lingard is a new contributor. Be nice, and check out our Code of Conduct.












                                David Lingard is a new contributor. Be nice, and check out our Code of Conduct.
















                                Thanks for contributing an answer to Mathematica Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                Use MathJax to format equations. MathJax reference.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f207540%2fslow-computation-of-recursive-sequences%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown









                                Popular posts from this blog

                                Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...