# Plotting non-linear recursive sequence [closed]

I'm a total noob with Mathematica, and while trying to plot the following, I get several error messages. What am I doing wrong?

O[n_] := O[n] = 0.7*O[n - 1] + 0.002*O[n - 1]*M[n - 1] ;

M[n_] := M[n] = 1.2*M[n - 1] - 0.001*O[n - 1]*M[n - 1] ;

O[0] := 150;

M[0] := 200;

Show[{DiscretePlot[{O[i], M[i]}, {i, 1, 10}]}]

• O is a protected symbol; try a different name, preferably starting with a lower case letter. – b.gates.you.know.what Apr 10 '15 at 20:34
• Thank you, that fixed one of the problems, I'm still getting: Series::ivar: 1 is not a valid variable. >> – Lucif3r Apr 10 '15 at 20:36
• Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. – bbgodfrey Apr 10 '15 at 20:46
• Related: (63524) – Mr.Wizard Jan 19 '17 at 23:34
• Your code works as written after replacing O with o and M with m. I am therefore closing this question as a simple mistake. – Mr.Wizard Jan 19 '17 at 23:37

a[n_] := 0.7 a[n - 1] + 0.002 a[n - 1] b[n - 1];

b[n_] := 1.2 b[n - 1] - 0.001 a[n - 1] b[n - 1];

a[0] := 150;

b[0] := 200;

ListPlot[
Transpose@Table[{a[n], b[n]}, {n, 1, 10}],
PlotLegends -> {"a", "b"}]


• That does it, Thank you Mr. Stork! – Lucif3r Apr 10 '15 at 20:47
• @JohnWayne360 You're welcome. Perhaps you could upvote my answer, and click on the check mark to accept it. – David G. Stork Apr 10 '15 at 20:52
• I will up-vote once I reach the required reputation level. Promise. On a different note, it never occurred to me how computationally expensive the sequence could get. My moderately powerful laptop can't seem to get past 15 iterations. Once again, many thanks. – Lucif3r Apr 10 '15 at 23:26

You can also use RecurrenceTable, NestList, and the memoized version of the method in @David's answer:

ClearAll[rt1, rt2, rt3, aa, bb]
rt1 = Transpose@RecurrenceTable[{a[n] == 0.7 a[n - 1] + 0.002 a[n - 1] b[n - 1],
b[n] == 1.2 b[n - 1] - 0.001 a[n - 1] b[n - 1],
a[0] == 150, b[0] == 200}, {a, b}, {n, 0, #}] &;

rt2 = Transpose[NestList[{0.7 #[[1]] + 0.002 #[[1]] #[[2]],
1.2 #[[2]] - 0.001 #[[1]] #[[2]]} &, {150, 200}, #]] &;

aa[n_] := aa[n] = 0.7 aa[n - 1] + 0.002 aa[n - 1] bb[n - 1];
bb[n_] := bb[n] = 1.2 bb[n - 1] - 0.001 aa[n - 1] bb[n - 1];
aa[0] = 150; bb[0] = 200;
rt3 = Transpose@Table[{aa[n], bb[n]}, {n, 1, #}] &;

Row[ListPlot[#@100, BaseStyle -> PointSize[Large],
ImageSize -> 300] & /@ {rt1, rt2, rt3}, Spacer[5]]


• Thank you Kguler! Could you explain to me the difference between your code and the one above? Yours seems to run much faster. Why is that? – Lucif3r Apr 10 '15 at 23:37
• @JohnWayne360, my pleasure. Re how RecurrenceTable and NestList work please see the linked docs pages. – kglr Apr 11 '15 at 0:15