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.

2.3. NUMERICAL SOLUTION OF ODES 89<br />

2.3.1 Finite Di®erence Approximations<br />

A tool knows exactly how it is meant to be handled, while the user of<br />

the tool can only have an approximate idea.<br />

Milan Kundera, Czech author, critic (1929{)<br />

Consider a general function y(x) as schematically depicted by the solid curved<br />

line in Figure 2.21. The independent variable has been taken to be x, butit<br />

could just as well be the time t. It is desired to ¯nd, say, the ¯rst and second<br />

Q<br />

x–h<br />

h<br />

y(x–h)<br />

P<br />

y(x)<br />

h<br />

R<br />

y(x+h)<br />

x x+h<br />

Figure 2.21: Obtaining ¯nite di®erence approximations to derivatives.<br />

derivatives of y at an arbitrary point P on the curve located at the horizontal<br />

position x. Assuming that h is small, two neighboring points R and Q located<br />

at x + h and x ¡ h, respectively, are considered. At point R, the vertical height<br />

is y(x + h) andatQ it is y(x ¡ h).<br />

Since h is assumed to be small, y(x + h) can be Taylor expanded in powers<br />

of h about h = 0, neglecting terms of, say, order h 4 (i.e., O(h 4 )) and higher.<br />

> restart:<br />

> eq1:=y(x+h)=taylor(y(x+h),h=0,4);<br />

eq1 := y(x + h) =<br />

y(x)+D(y)(x) h + 1<br />

2 (D(2) )(y)(x) h2 + 1<br />

6 (D(3) )(y)(x) h3 +O(h4 )<br />

The O(h4 )termineq1 can be removed with the convert(polynom) command.<br />

> eq1b:=convert(eq1,polynom);<br />

eq1b := y(x + h) =y(x)+D(y)(x) h + 1<br />

2 (D(2) )(y)(x) h2 + 1<br />

6 (D(3) )(y)(x) h3 Similarly y(x ¡ h) is Taylor expanded and the fourth-order term removed.

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

Saved successfully!

Ooh no, something went wrong!