1

If I have a system of recursive sequences like

x[n+1]=2x[n]+5(y[n])^2

y[n+1]=.5x[n]-3(y[n])^2

How can I plot it as a curves {x[n],n} and {y[n],n} in the same figure?? When I work with this code, I get the error as in the image![enter image description here]1

Raafat
  • 13
  • 2
  • 1
    Check this http://mathematica.stackexchange.com/questions/63524/plotting-two-recursive-functions?rq=1 – zhk Jan 19 '17 at 05:37
  • What initial conditions, `{x[1], y[1]} do you wish? – bbgodfrey Jan 19 '17 at 05:50
  • Thank you very much! "But when I copied this code in Mathematica 7. I get the error message: ListLinePlot::optx: Unknown option PlotLegends in ListLinePlot[{{1.,22.,705.25},{2.,-11.5,-385.75}},<<4>>,PlotLegends->{x,y}]. >>" – Raafat Jan 19 '17 at 14:25
  • @Raafat Load the package. << PlotLegends` – zhk Jan 19 '17 at 15:23
  • @Raafat Mathematica 7 does not have PlotLegends; you will need to load the package as MMM says but also use PlotLegend with no s, and parameters for the two options are not the same. – Mr.Wizard Jan 19 '17 at 23:29
  • Thank you Mr. Wizard, it is with no "s". – Raafat Jan 20 '17 at 09:05

1 Answers1

3

RecurrenceTable will be useful here. Note, I choose random initial conditions.

sol = RecurrenceTable[{x[n + 1] == 2  x[n] + 5 (y[n])^2, 
y[n + 1] == 0.5  x[n] - 3 (y[n])^2, x[0] == 1, y[0] == 2}, {x, 
y}, {n, 0, 2}, WorkingPrecision -> MachinePrecision];

ListLinePlot[Transpose@sol, 
 PlotStyle -> {Directive[Red, Thick], 
   Directive[Blue, AbsoluteDashing[{10, 10}]]}, Joined -> True, 
 Frame -> True, FrameLabel -> (Style[#, 22, Bold] & /@ {"n", ""}), 
 PlotLegends -> {x,  y}]

enter image description here

You can also use @David G. Stork method.

x[n_] := 2  x[n - 1] + 5 (y[n - 1])^2;  
y[n_] := 0.5  x[n - 1] - 3 (y[n - 1])^2;
x[0] := 1;    
y[0] := 2;    
ListLinePlot[Transpose@Table[{x[n], y[n]}, {n, 0, 2}], 
 PlotLegends -> {"x", "y"}]
zhk
  • 11,939
  • 1
  • 22
  • 38