1
$\begingroup$

How do I plot the Lorenz attractor given by the following code, inside an ellipsoid.

I have two things with me:

  1. The Lorenz system with P=6.06739, b=2.6678, r=30 and x,y,z are functions of time.

    eq1 = x'[t] == P (y[t] - x[t]);
    
    eq2 = y'[t] == r*x[t] - y[t] - x[t] z[t];
    
    eq3 = z'[t] == x[t] y[t] - b*z[t];
    
    sol = NDSolveValue[{eq1, eq2, eq3, x[0] == 1, y[0] == 5, z[0] == 10}, {x, y, z}, {t, 0, 30}];
    
    p1 = ParametricPlot3D[{sol[[1]][t], sol[[2]][t], sol[[3]][t]}, {t, 0, 30}]
    
  2. The equation of an ellipsoid with P=6.06739, r=30 and x,y,z are functions of time.

$$ x^2+y^2+(z-P-r)^2=2 $$ The result that I am looking for is: the trajectories of the Lorenz system must remain completely within the ellipsoid.

New contributor
Math_student is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
8
  • 1
    $\begingroup$ Just to be clear: do you want to create a plot that shows the portions of the trajectory inside the given ellipsoid, and omit the portions of the trajectory outside the ellipsoid? (If so, look into the RegionFunction option.) Or do you have something else in mind? $\endgroup$ Jun 20 at 13:57
  • 1
    $\begingroup$ Please link to the paper from where you saw the equation in your question. $\endgroup$ Jun 20 at 14:09
  • $\begingroup$ The ellipsoid in (45) of the linked paper is different from the ellipsoid you've provided, and so are the evolution equations (36–38). Is this intentional? $\endgroup$ Jun 20 at 14:52
  • $\begingroup$ The equation of ellipsoid which I have provided is something that I have obtained. However, is it possible to get the Lorenz attractor inside the ellipsoid defined in (45) of the paper? Also, the Eqs.(36)-(38) are the same as in the code. @MichaelSeifert $\endgroup$ Jun 20 at 15:14
  • $\begingroup$ Equation (36) in the linked paper has P r (y[t] - x[t]) rather than P (y[t] - x[t]). Is that a typo in what you've provided? $\endgroup$ Jun 20 at 15:19

1 Answer 1

7
$\begingroup$

Unless I've done something wrong, it does not appear that the trajectories stay inside the given ellipsoid. The given ellipsoid can be rewritten as $$ \frac{P}{b} x^2 + \frac{1}{b} y^2 + \left( z - \frac{P+r}{2} \right)^2 - \left( \frac{P+r}{2} \right)^2 \leq 0. $$ So we can define this function and superimpose it in p1:

ellipsoidfn[x_, y_, z_] = P x^2/b + y^2/b + (z - (P + r)/2)^2 - ((P + r)/2)^2 ;
p2 = ContourPlot3D[ellipsoidfn[x, y, z] == 0, {x, -20, 20}, {y, -20, 20}, {z, 0, 40}, Mesh -> False, ContourStyle -> Opacity[0.8]];
Show[p1, p2]

enter image description here

Alternately, one can tell Mathematica to render the trajectory with a different color inside & outside the ellipsoid:

ParametricPlot3D[{sol[[1]][t], sol[[2]][t], sol[[3]][t]}, {t, 0, 30}, 
   ColorFunction -> Function[{x, y, z, u}, If[ellipsoidfn[x, y, z] > 0, Red, Blue]], ColorFunctionScaling -> False]

enter image description here


Concerning the edited question: we can run the same code above with the new parameters and with

ellipsoidfn[x_, y_, z_] = x^2 + y^2 + (z - (P + r))^2 - 2;

If we do this, however, the trajectory does not stay within the new ellipsoid; in fact, as far as I can tell, it does not even enter the new ellipsoid. enter image description here

$\endgroup$
12
  • $\begingroup$ Is it possible to write the evolution equations and the ellipsoid equation in a single code? Since using the "Show[ ]" function only merges the two separate graphs p1 and p2. $\endgroup$ Jun 20 at 15:36
  • 1
    $\begingroup$ @Math_student: I'm not aware of any way to plot a parametric curve and a surface using the same command. However, I've added another way to visualize the portions of the curve that are inside and outside of the ellipsoid that works solely within ParametricPlot. $\endgroup$ Jun 20 at 15:55
  • $\begingroup$ That's something very new, thanks! Also, the ellipsoid equation which you have used is the one that I posted or from the linked paper? $\endgroup$ Jun 20 at 16:00
  • 1
    $\begingroup$ @Math_student If what Michael showed is not what you want, then it is still unclear what you would consider the "correct" result. You need to explain more clearly what you actually want. $\endgroup$
    – MarcoB
    Jun 20 at 16:35
  • 1
    $\begingroup$ @Math_student: Yes, I'm also unclear on what could be considered a "correct" result. Either this trajectory of this ODE system is wrong (which I think is unlikely) or this trajectory does not stay inside the ellipsoid you've provided. $\endgroup$ Jun 20 at 17:01

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