16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.2. SECOND-ORDER MODELS 127<br />

On entering the given di®erential equation, Vectoria observes that the output<br />

in de is expressed in terms of the prime notation.<br />

> de:=2*x*diff(y(x),x,x)+(1-2*x)*diff(y(x),x)-x^2*y(x)=0;<br />

de := 2 x y 00 +(1¡ 2 x) y 0 ¡ x2 y =0<br />

The initial condition is speci¯ed, as well as the value of X and a parameter d<br />

that will control the spacing of the numerical points in the graph.<br />

> ic:=y(0)=1,D(y)(0)=0: X:=4: d:=8:<br />

Using dsolve, an attempt is made to analytically solve de for y(x).<br />

> dsolve(fde,icg,y(x)); #no analytic solution<br />

No output is generated, Maple being unable to provide an analytic answer. Although<br />

she has now omitted it, Vectoria had included infolevel[dsolve]:=5;<br />

prior to the dsolve command. On doing so she was able to view a very lengthy<br />

list of unsuccessful ODE solving methods tried by Maple. If you wish to see<br />

these attempts, include the above infolevel command.<br />

To generate a procedure for numerically evaluating y and y 0 at arbitrary x,<br />

Vectoria includes the numeric option in dsolve and requests that the output<br />

be given as a \list procedure."<br />

> numsol:=dsolve(fde,icg,y(x),numeric,output=listprocedure);<br />

numsol := [x =(proc(x) ::: end proc); y=(proc(x) ::: end proc);<br />

y 0 =(proc(x) ::: end proc)]<br />

Evaluating y(x) withthenumsol procedure will generate a numerical answer<br />

for y at x when the value of x is supplied as the argument of Ynum de¯ned<br />

below. Then, entering Ynum(X) gives the numerical value of y at X (4, here),<br />

the answer being given to 18 digits, more than the \normal" 10-digit accuracy.<br />

> Ynum:=eval(y(x),numsol): Ynum(X);<br />

41:1065491999371986<br />

Thus, y ¼ 41 at x = X = 4. A similar command structure is used to numerically<br />

evaluate the derivative of y, yielding y 0 ¼ 76 at X.<br />

> Ynumder:=eval(diff(y(x),x),numsol): Ynumder(X);<br />

75:6306643796735756<br />

Vectoria will use a do loop to systematically calculate series solutions of de as<br />

a function of the order n, terms of order xn and larger being neglected. The<br />

do loop will include a conditional statement that will terminate the loop when<br />

the absolute percentage di®erence j100 (ynum(X)¡yseries(X))=ynum(X)j drops<br />

below one percent. As a \seed number" to implement the conditional statement,<br />

she calculates the absolute percentage di®erence between the starting value of<br />

y(0) = 1 and the numerical value of y at x = X =4.<br />

> percent[0]:=abs(evalf(100*(Ynum(X)-1)/Ynum(X))); #seed<br />

percent 0 := 97:56729762<br />

The do loop runs from 1 to 50, the number 50 being chosen to be large enough<br />

to achieve a percentage error below one percent. The loop will calculate the

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

Saved successfully!

Ooh no, something went wrong!