Message Boards Message Boards

Overflow problem implementing Euler's method

15 Replies

I can not do the comparison of two graphs like that

Yes, that problem has been solved. I am so grateful for your help. Both of you

You can probably simplify things by vectorizing your code.

Instead of doing everything in triplicate and having lots of code repetition, you can perhaps just do this:

\[Alpha] = 0.9;
\[Beta] = 0.2;
\[Gamma] = 0.4;

f[{x_, y_, z_}] := {z + (y - \[Alpha])*x, 1 - \[Beta]*y - x^2, -x - \[Gamma]*z}

Q[a_, b_, c_, h_, NN_] := (
 u[0] = {a, b, c};
 Do[
   u[n + 1] = u[n] + h*f[u[n] + h/2*f[u[n]]],
   {n, 0, NN}]);

Q[1, 3, 2, 0.1, 200];
X = Interpolation[Table[{n, u[n]}, {n, 0, 2000}]];
ParametricPlot3D[X[t], {t, 0, 2000}]
POSTED BY: Arnoud Buzing

Ok, thanks. But is not wrong the code above right?

Your code is fine, just trying to show you how to make it potentially simpler.

POSTED BY: Arnoud Buzing

Thank you very much! I will keep it in mind!

Is it possible to contrast on the same axis system the two ParametricPlots from the first two cases on the [0,200]?

Yes, for example with this code:

MakePlot[{\[Alpha]_, \[Beta]_, \[Gamma]_}, {a_, b_, c_}, h_, max_Integer] := Module[{u, if},
  f[{x_, y_, z_}] := {z + (y - \[Alpha])*x, 1 - \[Beta]*y - x^2, -x - \[Gamma]*z};
  u[0] = {a, b, c};
  Do[u[n + 1] = u[n] + h*f[u[n] + h/2*f[u[n]]], {n, 0, max}];
  if = Interpolation[Table[{n, u[n]}, {n, 0, max/h}]];
  ParametricPlot3D[if[t], {t, 0, 2000}]
]

You can do this:

plot1 = MakePlot[{0.9, 0.2, 1.2}, {1, 3, 2}, 0.1, 200]
plot2 = MakePlot[{0.9, 0.2, 0.4}, {1, 3, 2}, 0.1, 200]

And then combine them:

Show[{plot1, plot2}]
POSTED BY: Arnoud Buzing

Here is another idea, using AnimationVideo. Same MakePlot function, but with an explicit PlotRange to keep that constant for any parameter choice:

MakePlot[{\[Alpha]_, \[Beta]_, \[Gamma]_}, {a_, b_, c_}, h_, 
  max_Integer] := Module[{u, if},
  f[{x_, y_, z_}] := {z + (y - \[Alpha])*x, 
    1 - \[Beta]*y - x^2, -x - \[Gamma]*z};
  u[0] = {a, b, c};
  Do[u[n + 1] = u[n] + h*f[u[n] + h/2*f[u[n]]], {n, 0, max}];
  if = Interpolation[Table[{n, u[n]}, {n, 0, max/h}]];
  ParametricPlot3D[if[t], {t, 0, 2000}, 
   PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}]
  ]

Then:

AnimationVideo[
 MakePlot[{0.9, 0.2, t}, {1, 1, 1}, 0.02, 1000],
 {t, 0.0, 2.0}]

Generates this video:

https://www.wolframcloud.com/obj/2d831a2f-4c28-4881-82bc-3bc95c88bbad

POSTED BY: Arnoud Buzing

Amazing!!! Could I do the same for the

Plot[{X[t],Y[t],Z[t]},{t,0,200},PlotLegends->"Expressions"]

I have tried to do what you have advised me. Could you take a look please and tell me your opinion? Thank you in advance.

Not sure what opinion you're looking for, but that looks beautiful to me?

Problem solved?

POSTED BY: Arnoud Buzing
POSTED BY: Henrik Schachner
POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract