16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.3. NUMERICAL SOLUTION OF ODES 103<br />

The semi-implicit algorithm is now implemented in the following recipe,<br />

taking a total of 5000 time steps of size h =0:004.<br />

> restart: Digits:=10: total:=5000: h:=0.004:<br />

The parameter values are entered, with g at the lower end of its range.<br />

> a:=1: b:=0.5: beta:=79.67: g:=0.1: alpha:=73: sigma:=13:<br />

Initially, we take x0 =4,y0 =0:4, and z0 =0:1.<br />

> t[0]:=0: x[0]:=4: y[0]:=0.4: z[0]:=0.1:<br />

The initial plotting point is formed, and the starting time of the do loop that<br />

iterates the algorithm is recorded.<br />

> pnt[0]:=[t[0],x[0],y[0]]: begin:=time():<br />

> for n from 0 to total do<br />

The various coe±cients are evaluated on the nth step.<br />

> N[n]:=x[n]+y[n]+z[n];<br />

> A1[n]:=1+h*(b-a)+h*g*(N[n]+x[n])+h*beta*z[n];<br />

> B1[n]:=h*g*x[n];<br />

> C1[n]:=h*(beta+g)*x[n];<br />

> D1[n]:=h*g*N[n]*x[n]+h*beta*x[n]*z[n];<br />

> A2[n]:=h*g*y[n]-h*beta*z[n];<br />

> B2[n]:=1+h*(sigma+b)+h*g*(N[n]+y[n]);<br />

> C2[n]:=h*g*y[n]-h*beta*x[n];<br />

> D2[n]:=h*g*N[n]*y[n]-h*beta*x[n]*z[n];<br />

> A3[n]:=h*g*z[n];<br />

> B3[n]:=h*g*z[n]-h*sigma;<br />

> C3[n]:=1+h*(alpha+b)+h*g*(N[n]+z[n]);<br />

> D3[n]:=h*g*N[n]*z[n];<br />

The linear equations for xn+1, yn+1, zn+1 are entered,<br />

> E1:=A1[n]*x[n+1]+B1[n]*y[n+1]+C1[n]*z[n+1]=x[n]+D1[n];<br />

> E2:=A2[n]*x[n+1]+B2[n]*y[n+1]+C2[n]*z[n+1]=y[n]+D2[n];<br />

> E3:=A3[n]*x[n+1]+B3[n]*y[n+1]+C3[n]*z[n+1]=z[n]+D3[n];<br />

and numerically solved.<br />

> sol[n+1]:=(fsolve(fE1,E2,E3g,fx[n+1],y[n+1],z[n+1]g));<br />

The solution is assigned and the values of xn+1, yn+1, andzn+1 are recorded<br />

at time tn+1 = tn + h.<br />

> assign(sol[n+1]);<br />

> x[n+1],y[n+1],z[n+1];<br />

> t[n+1]:=t[n]+h;<br />

Finally, a plotting point is formed and the loop ended.<br />

> pnt[n+1]:=[t[n+1],x[n+1],y[n+1]];<br />

> end do:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!