8.1 Back to Basics

   

 
Java Number Cruncher: The Java Programmer's Guide to Numerical Computing
By Ronald  Mak

Table of Contents
Chapter  8.   Solving Differential Equations Numerically

8.1 Back to Basics

What does the derivative of a function tell us? If our function is y ( x ), then its derivative y '( x ) gives us the value of the slope of y ( x ) for each value of x ( assuming , of course, that y ( x ) is continuous and has a derivative there). In other words, the derivative of a function tells us, at each point, the direction of the function at that point.

So, if we're given the differential equation y '( x ) with the initial condition y ( x ) = y , we can use the values of y '( x ) to get approximations to the values of y ( x ) over an interval from x to x n .

The basic idea behind solving differential equations is really that simple. If we're given the initial condition y ( x ) = y , we start with the point ( x , y ), since the solution must go through that point. The value of y '( x ) tells us which direction to go, and so we go in that direction until we reach x 1 , giving us point ( x 1 , y 1 ). See Figure 8-1. At ( x 1 , y 1 ), we change direction according to the value of y '( x 1 ) and go in that new direction until we reach x 2 , giving us the point ( x 2 , y 2 ). There, we change direction according to the value of y '( x 2 ) and go until we reach x 3 . This continues until we reach x n . Then our entire path , the points ( x , y ), ( x 1 , y 1 ), and so on through ( x n , y n ), is our approximation to the solution function y ( x ) over the interval [ x , x n ].

Figure 8-1. Using the slope value y ' (x ) to provide the direction (bold arrow) to get from the point ( x , y ) to the point ( x 1 , y 1 ).

graphics/08fig01.jpg

How accurate can this solution be? Let's assume that we always go the same horizontal distance h before we change direction:

graphics/08equ04.gif


Then, of course, smaller values of h will result in more accurate solutions, since we'll have more frequent "course corrections" as we trace out the approximation to the solution function. However, smaller h values mean more steps from x to x n , and the increased amount of computation not only requires more time but also can generate more roundoff errors.

Besides roundoff errors, there are other sources of error. If the true solution y ( x ) is a curve (instead of a straight line), then when we head off from the initial point ( x , y ), we're going to go off course from the y ( x ) how big this local error is depends on the size of h. We see this error in Figure 8-1 as the vertical distance between ( x 1 , y 1 ) and ( x 1 , y ( x 1 )). But at ( x 1 , y 1 ), we don't get to make up for that local error. We simply head off in the new direction from the already off-course ( x 1 , y 1 ) according to the value of y '( x 1 ), and so we make a new local error on top of the previous one. Thus, at the end, we have a cumulative error.

Figure 8-2 shows the effects of these errors (albeit with a relatively large value of h ) solving the differential equation

graphics/08equ05.gif


Figure 8-2. The effects of cumulative error in the numerical solution of an initial value problem. The dot represents initial condition y (2) = 0. The analytical solution y = x 2 - 4 is the smooth curve. Compare that to the numerical solution consisting of the line segments. The width of each interval h = 1.825, resulting in the large error. The error would be less with a smaller value of h .

graphics/08fig02.jpg

with the initial condition y (2) = 0. The actual solution is

graphics/08equ06.gif


Figure 8-2 shows the numerical approximation of the solution function on both sides of the initial point.


   
Top
 


Java Number Cruncher. The Java Programmer's Guide to Numerical Computing
Java Number Cruncher: The Java Programmers Guide to Numerical Computing
ISBN: 0130460419
EAN: 2147483647
Year: 2001
Pages: 141
Authors: Ronald Mak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net