6

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Abudin
  • 161
  • 3

2 Answers2

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
  • 20,103
  • 2
  • 43
  • 84
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 missing motivation
  • 124,525
  • 11
  • 401
  • 574