Animating the Lorenz Equations

6

2

I am trying to use the Animate command to vary a parameter of the Lorenz Equations in 3-D phase space and I'm not having much luck.

The equations are:

$\begin{align*} \dot{x} &= \sigma(y-x)\\ \dot{y} &= rx-y-xz\\ \dot{z} &= xy-bz \end{align*}$

Where $\sigma, r, b > 0$ are parameters to be varied.

Insofar, I am using the NDSolve command to numerically integrate these equations, then ParametricPlot3D and the Evaluate command to plot them.

Just for starters, I am trying to create an animate command to vary $\sigma$ for example from 0 to 10. Can anyone guide me in the right direction? My code looks like this so far:


σ = 10;

NDSolve[{x'[t] == σ (y[t] - x[t]), 
         y'[t] == 28 x[t] - y[t] - x[t] z[t], z'[t] == x[t] y[t] - 8/3 z[t], 
         x[0] == z[0] == 0, y[0] == 2}, {x, y, z}, {t, 0, 25}]

Animate[ParametricPlot3D[
  Evaluate[{x[t], y[t], z[t]} /. solution], {t, 0, 25}], {σ, 0, 25},
  AnimationRunning -> False]

This will generate an animated plot but obviously as σ varies, nothing is changing since I am not implementing new NDSolve commands. Can anyone guide me as to how I can implement successive NDSolve's inside the animate command? Thank you

EDIT: I am using $r=28$ and $b=\frac83$ in place of r and b in my code.

Abudin

Posted 2013-04-24T08:36:52.017

Reputation: 61

I'm using Mathematic 10 on Linux and I'm unable to get these animations working. I succeed to get the result box (as show in the screenshot), but the animate button is stuck, I can't move it. Any clue ?

– Pol Dellaiera – 2016-02-23T12:53:24.010

1Have a look at ParametricNDSolveValue. – b.gates.you.know.what – 2013-04-24T08:38:43.060

Can I apply ParametricNDSolveValue or ParametricNDSolve to animations in 3D? – Abudin – 2013-04-24T09:19:28.353

Yes, please give it a try. – b.gates.you.know.what – 2013-04-24T10:08:21.823

1I don't think my version of mathematica actually has those functions in them Lol.. I have mathematica 8.0, are these 9.0 commands? – Abudin – 2013-04-24T10:21:20.170

Indeed, they are new in 9.0. – b.gates.you.know.what – 2013-04-24T10:23:05.827

Unfortunate :(, I have made some progress, not enough though. I have currently been able to Correctly animate my lorenz equations using time, but insofar I haven't been able to alter those parameters. – Abudin – 2013-04-24T10:30:21.320

For visualization, see also this answer by @kguler.

– Jens – 2013-04-24T17:14:16.183

Answers

6

You can define a solution function depending on your parameter and then use it for the animation :

sol[sigma_] := {x, y, z} /. 
 NDSolve[{x'[t] == sigma (y[t] - x[t]), y'[t] == 28 x[t] - y[t] - x[t] z[t], 
 z'[t] == x[t]*y[t] - 8/3 z[t], x[0] == z[0] == 0, y[0] == 2}, 
 {x, y, z}, {t, 0, 25}][[1]]

Animate[
 With[{f = sol[sigma]},
  ParametricPlot3D[{f[[1]][t], f[[2]][t], f[[3]][t]}, {t, 0, 25}]
 ], {sigma, 0, 25}, AnimationRunning -> False
]

b.gates.you.know.what

Posted 2013-04-24T08:36:52.017

Reputation: 18 845

For an animation, you probably want to set a fixed PlotRange for the ParametricPlot (unless you actually want a zoom effect) as well as include option PerformanceGoal->"Quality". – murray – 2013-04-24T15:11:26.760

@murray Thanks, very good suggestions. – b.gates.you.know.what – 2013-04-24T15:26:59.497

6

If you just want to do a simple cartoon (as opposed to evaluating the solution components of the Lorenz equations at particular values), you can just directly extract the points generated by NDSolve[]. Here's one way to go about it:

sol[σ_] := 
 Transpose[Through[{x, y, z}["ValuesOnGrid"] /. 
           First @ NDSolve[{x'[t] == σ (y[t] - x[t]), 
                            y'[t] == 28 x[t] - y[t] - x[t] z[t], 
                            z'[t] == x[t] y[t] - 8 z[t]/3,
                            x[0] == z[0] == 0, y[0] == 2}, {x, y, z}, {t, 0, 25}]]]

Animate[Graphics3D[{Red, Tube[sol[σ]]}, Axes -> True, 
                   PlotRange -> {{-30, 30}, {-30, 30}, {0, 50}}],
        {σ, 0, 25}, AnimationRunning -> False]

A Lorenz cartoon

J. M.'s ennui

Posted 2013-04-24T08:36:52.017

Reputation: 115 520