3
$\begingroup$

I'm working on a project in order to plot a graphical method for finite-difference equations called cobweb method. The next figure was succesful try for

$$x_{t+1} = Rx_t - \frac{R}{2000}x_t^2$$

enter image description here

But, when I try with

$$x_{t+1} = \cos{x_t},$$

and copy-paste the code I used before, the result was

enter image description here

For some reason Joined->True doesn't draw all the lines. Changing a litle bit the number of point plotted, from 17 to 16, the figure is correct

enter image description here


There is a problem, but, where? My code is the following

difEqu[x_] := N[Cos[x]]

traFin = {{0.4,0},{0.4,0.921061},{0.921061,0.921061},{0.921061,0.604976},
 {0.604976,0.604976},{0.604976,0.822516},{0.822516,0.822516},{0.822516,0.68038},
 {0.68038,0.68038},{0.68038,0.777334},{0.777334,0.777334},{0.777334,0.712786},
 {0.712786,0.712786},{0.712786,0.756543},{0.756543,0.756543},{0.756543,0.727213},
 {0.727213,0.727213},{0.727213,0.74703},{0.74703,0.74703},{0.74703,0.73371},
 {0.73371,0.73371},{0.73371,0.742695},{0.742695,0.742695},{0.742695,0.736649},
 {0.736649,0.736649},{0.736649,0.740724},{0.740724,0.740724},{0.740724,0.73798},
 {0.73798,0.73798},{0.73798,0.739829},{0.739829,0.739829},{0.739829,0.738584}}

extremos = {{0.4,0},{0.739829,0.738584}}

Show[
 Plot[
  Evaluate[
   {Legended[Style[difEqu[x], RGBColor[0., 0., 1.], Thickness[0.004]],"x[0] = 0.6"],
   Legended[Style[x, RGBColor[0., 0., 0.], Thickness[0.004], Dashed],"Identidad"]}
  ],
 {x, 0, 1},
 PlotTheme -> "Scientific",
 ImageSize -> Large,
 PlotRange -> Full,
 FrameLabel ->
  {Style["x (t)", FontSize -> 35],
  Style["x (t+1)", FontSize -> 35]},
  LabelStyle -> {FontFamily -> "Arial", 20, RGBColor[0., 0., 0.]}
 ],
 ListPlot[
  {traFin, extremos},
  PlotStyle -> {{RGBColor[1., 0., 0.],Thickness[0.001]},{RGBColor[1., 0., 0.]}},
  Joined -> {True, False}
 ]
]

I get traFin with another code. The number of iterations here is 16, i.e.

$$x_{16+1} = \underbrace{x(x(\cdots(}_{\text{16 times}}0.4) = 0.738584.$$


Edit: The following code corresponds to 17 iterations:

difEqu[x_] := N[Cos[x]]

traFin = {{0.4,0},{0.4,0.921061},{0.921061,0.921061},{0.921061,0.604976},{0.604976,0.604976},{0.604976,0.822516},{0.822516,0.822516},{0.822516,0.68038},{0.68038,0.68038},{0.68038,0.777334},{0.777334,0.777334},{0.777334,0.712786},{0.712786,0.712786},{0.712786,0.756543},{0.756543,0.756543},{0.756543,0.727213},{0.727213,0.727213},{0.727213,0.74703},{0.74703,0.74703},{0.74703,0.73371},{0.73371,0.73371},    {0.73371,0.742695},{0.742695,0.742695},{0.742695,0.736649},        {0.736649,0.736649},{0.736649,0.740724},{0.740724,0.740724},{0.740724,0.73798},{0.73798,0.73798},{0.73798,0.739829},{0.739829,0.739829},{0.739829,0.738584},{0.738584,0.738584},{0.738584,0.739423}}

extremos = {{0.4,0},{0.739829,0.738584}}

Show[
 Plot[
  Evaluate[
   {Legended[Style[difEqu[x], RGBColor[0., 0., 1.], Thickness[0.004]],"x[0] = 0.6"],
   Legended[Style[x, RGBColor[0., 0., 0.], Thickness[0.004], Dashed],"Identidad"]}
  ],
 {x, 0, 1},
 PlotTheme -> "Scientific",
 ImageSize -> Large,
 PlotRange -> Full,
 FrameLabel ->
  {Style["x (t)", FontSize -> 35],
  Style["x (t+1)", FontSize -> 35]},
  LabelStyle -> {FontFamily -> "Arial", 20, RGBColor[0., 0., 0.]}
 ],
 ListPlot[
  {traFin, extremos},
  PlotStyle -> {{RGBColor[1., 0., 0.],Thickness[0.001]},{RGBColor[1., 0., 0.]}},
  Joined -> {True, False}
 ]
]
$\endgroup$
2
  • $\begingroup$ Unable to reproduce with the code above. The plot looks fine. $\endgroup$ Commented Sep 24, 2020 at 0:21
  • $\begingroup$ @RohitNamjoshi Yes, the code above corresponds to 16 iterations. I'll edit the post in order to include the code with the error, 17 iterations. $\endgroup$ Commented Sep 24, 2020 at 0:43

1 Answer 1

5
$\begingroup$

The problem you are running into is that the ListPlot is cropping the plot-region in an unlucky way. Put PlotRange->All as final option into the ListPlot call and you should be fine.

You could have found this issue yourself by inspecting the plots separately.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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