# # prog4a.mpl -- Compute the Lorenz System # Written Nov 21, 2002 by Eric Olson for Mathematics 483 # # For information about the Lorenz System see section 4.3 in Applied # Analysis of the Navier Stokes Equations by Doering and Gibbon. # # For information about the Euler and RK methods used in solving this # equation see chapter 4 in Numerical Analysis for Applied # Mathematics, Science and Engineering by Greenspan and Casulli. # kernelopts(printbytes=false): with(linalg): f:=x->[-10.0*x[1]+10.0*x[2], 28.0*x[1]-x[2]-x[1]*x[3], x[1]*x[2]-(8.0/3.0)*x[3]]; a:=[2.0,3.0,15.0]; printf("Prog4a.mpl -- Compute the Lorenz System\n"); printf("\nEuler's Method:\n"); n:=64: for i from 0 to 10 do y:=a: h:=1.0/n: for j from 1 to n do y:=y+h*f(y); od: printf("n=%d, y(1)=[%g, %g, %g]\n", n,y[1],y[2],y[3]); n:=n*2: od: printf("\nRK2 Method:\n"); n:=64: for i from 0 to 10 do y:=a: h:=1.0/n: for j from 1 to n do k1:=h*f(y); k2:=h*f(y+k1); y:=y+0.5*(k1+k2); od: printf("n=%d, y(1)=[%g, %g, %g]\n", n,y[1],y[2],y[3]); n:=n*2: od: