1
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ Check this mathematica.stackexchange.com/questions/63524/… $\endgroup$ – zhk Jan 19 '17 at 5:37
  • $\begingroup$ What initial conditions, `{x[1], y[1]} do you wish? $\endgroup$ – bbgodfrey Jan 19 '17 at 5:50
  • $\begingroup$ 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}]. >>" $\endgroup$ – Raafat Jan 19 '17 at 14:25
  • $\begingroup$ @Raafat Load the package. << PlotLegends` $\endgroup$ – zhk Jan 19 '17 at 15:23
  • $\begingroup$ @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. $\endgroup$ – Mr.Wizard Jan 19 '17 at 23:29
3
$\begingroup$

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"}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ No, but I have an error when i do! $\endgroup$ – Raafat Jan 19 '17 at 14:56
  • $\begingroup$ @Raafat Doing what produces an error? $\endgroup$ – zhk Jan 19 '17 at 14:57
  • $\begingroup$ I have copied the code and use it in mathematica. But it gives the error message: " ListLinePlot::optx: Unknown option PlotLegends in ListLinePlot[{{1,22,705.25},{2,-11.5,-385.75}},PlotLegends->{x,y}]. >>" $\endgroup$ – Raafat Jan 19 '17 at 15:01
  • $\begingroup$ Thank you for help! the code does work. But without "PlotLegends -> {"x", "y"}"!! Do you have a solution to that ?! $\endgroup$ – Raafat Jan 19 '17 at 15:23
  • $\begingroup$ @Raafat load the package. << PlotLegends` $\endgroup$ – zhk Jan 19 '17 at 15:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.