3
$\begingroup$

I solved the Lorenz system by using Euler forward method (without using NDSolve). But I am not getting the attractor. The Mathematica code is as follows

Clear[x, y, z]
x[0] = 0; y[0] = 1; z[0] = 0;
Do[x[n + 1] = x[n] + .01 ( -3 ( x[n] - y[n])), {n, 0, 100}]
Do[y[n + 1] = y[n] + .01 (-x[n] z[n] + 28 x[n] - y[n]), {n, 0, 100}]
Do[z[n + 1] = z[n] + .01 (x[n] y[n] - z[n]), {n, 0, 100}]
Plot[{z[n], y[n], z[n]}, {n, 0, 100}]

Please help to solve the problem.

$\endgroup$
2
  • 1
    $\begingroup$ Greetings! Make the most of Mma.SE and take the tour now.Choose a meaningful name. Help us to help you, write an excellent question. Edit if improvable, show due diligence, give brief context, include minimum working examples of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$
    – rhermans
    Oct 1 '15 at 6:56
  • $\begingroup$ Your Plot command does not contain x[n] but instead has z[n] twice. $\endgroup$ Oct 1 '15 at 7:06
12
$\begingroup$

Another version:

euler[{x_, y_, z_}] := 
 {x + .01 (-3 (x - y)),y + .01 (-x z + 28 x - y),z + .01 (x y - z)}

steps = 1000;
init = {0, 1, 0};

sol = NestList[euler, init, steps];

(* ListLinePlot[Transpose@sol] *)
p = Interpolation /@ Transpose@sol;
Plot[Evaluate@Through@p@x, {x, 1, 1000}]

enter image description here

Edit (@belisarius comment)

ParametricPlot3D[
  Through@p@x, {x, 1, 1000}, 
  PlotPoints -> 1000,ColorFunction -> (Hue[#4] &)]

enter image description here

Edit 2

The OP works with Mathematica $5.0$. In this version the procedures ListLinePlot and ListPlot[..., Joined->true]are not introduced. With this edit it should work.

$\endgroup$
6
  • 2
    $\begingroup$ For your second plot probably p = Interpolation /@ Transpose@sol; ParametricPlot3D[ Through@p@x, {x, 1, 1000}] is cleaner $\endgroup$ Oct 1 '15 at 9:03
  • $\begingroup$ @belisarius Thank you, I edit this. $\endgroup$
    – user31001
    Oct 1 '15 at 9:11
  • $\begingroup$ Thank You. I have Mathematica 5. Is this run the above code. I am copy the code and run... they are shown some error... $\endgroup$ Oct 2 '15 at 9:13
  • $\begingroup$ @G Velmurugan It works with Mathematica 10.2 perfectly. I don't have Mathematica 5 and cannot help further. $\endgroup$
    – user31001
    Oct 2 '15 at 9:58
  • $\begingroup$ @G Velmurugan I have made an edit, so it should work in Mathematica 5.0. Unfortunately I can not test it. $\endgroup$
    – user31001
    Oct 2 '15 at 13:16
6
$\begingroup$

Try this

Clear[x, y, z]

x[n_] := x[n] = x[n - 1] + .01 (-3 (x[n - 1] - y[n - 1]))
y[n_] := y[n] = y[n - 1] + .01 (-x[n - 1] z[n - 1] + 28 x[n - 1] - y[n - 1])
z[n_] := z[n] = z[n - 1] + .01 (x[n - 1] y[n - 1] - z[n - 1])

x[0] = 0; 
y[0] = 1; 
z[0] = 0;

limitN = 1000;
resAll = Table[{x[n], y[n], z[n]}, {n, 0, limitN}];

ListLinePlot[{resAll[[;; , 1]], resAll[[;; , 2]], resAll[[;; , 3]]}, 
 PlotLegends -> {"x[n]", "y[n]", "z[n]"}, 
 PlotLabel -> "n=" <> ToString[limitN]]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank You. I have Mathematica 5. Is this run the above code. I am copy the code and run... they are shown some error... $\endgroup$ Oct 2 '15 at 9:13
  • $\begingroup$ @GVelmurugan Yes, it's the code for the shown plot. I don't get an error with version 10. What error do you get? $\endgroup$
    – Phab
    Oct 2 '15 at 9:22
  • $\begingroup$ Thank You Phab. I have download Mathematica 9 and install it. Now the code is works. Further, any query I will contact. $\endgroup$ Oct 3 '15 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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