Lesson goal: For loops and plotting the Lorenz Attractor

Previous: Graph a function | Home | Next: Animate a single pixel

Sometimes plotting mathematical equations is outright fun. The patterns that can be created are like no other. From the field of "dynamical systems and fractals," there is a system called the "Lorenz Attractor." There are three equations that govern it, one for $x$, one for $y$ and one for $z$, which are: $$x=x+d(a(y-x)),$$ $$y=y+d(bx-y-xz),$$ and $$z=z+d(xy-cz).$$

where $a$, $b$ and $c$ are constants. $d$ is also a constant, that must be small, like $d=0.01$. Here, $x$, $y$, and $z$ are coordinates that may be plotted using pset versus one another. Starting $x=1$, $y=1$, and $z=1$, choose values of $a$, $b$, and $c$, and see if you can plot the Lorenz Attractor. (Hint: Try $a=10$, $b=28$, and $c=8/3$ to start out. Use pset to plot $x$ vs $z$.)

Now you try. Try fixing the x=, y= and z= and the pset statements to plot the Lorenz Attractor.

Type your code here:


See your results here:

This code will not run. You have to fix the y= statement first to define your parabola (hint: try y=x^2). Next, you have to fix the pset statement to plot $x$ on the x-axis, and $y$ on the y-axis. Can you do it? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.