MM455 - Differential Equations

Lab #4 - Numerical Methods

There are many differential equations that cannot be solved exactly. In some of these cases it is sufficient to get a good approximation of the answer at a particular point. We will concentrate on differential equations given in the form y' = f( x, y ), with y( x0 ) = y0. We are to find an approximation for y( xn ).

Euler Method

We will divide the interval from x0 to xn into subintervals of width delta x. The endpoints of these intervals are x0, x1, x2, ... , xn. Since we are given the derivative y' = f( x, y ), we can find the slope of the tangent line at ( x0, y0 ). We can use this to approximate the value of the solution to our differential equation at x1. We will call this value y1. We will then repeat the process at ( x1, y1 ), using the derivative to approximate ( x2, y2 ). We will continue until we have an approximation for yn = y( xn ).

We are using y' to approximate the change in y. Here the approximation would be too high. If the graph were concave up, the approximation would be too low. Let's do an example where we start at y( 0 ) = 1 and wish to approximate y( 1 ). We will divide the interval into 10 subintervals, having width h = 0.1 each.

The function g( x ) is the exact solution to the differential equation . The option DisplayFunction -> Identity suppresses the output of the graph and the strange option DisplayFunction ->$DisplayFunction shows the graph. This is the output:

The dots are the estimates given by Euler's Method. How to get better estimates? One way is to decrease h, the distance between successive x values. Your first exercise is to decrease h to 0.05 and have the number of points double to 20.

Runge-Kutta Method

The Runge-Kutta method is the method used by Mathematica when it does a numeric differentiation solve: NDSolve[ ]. Here is the method over the interval [0, 1]:

 

The k1 is the approximation due to Euler. The subsequent refinements are a consequence of a Taylor Series expansion for y( xn + h ). Let's use Runge-Kutta on the above differential equation in order to compare the two methods. First the code:

And the results:

These results are incredible! They are virtually free of error with approximations equal to the exact solution for five decimal places! It is no wonder that it is the method of preference for solving differential equations numerically.

 

Exercises

1. Increase the number of points in the Euler approximation to 20. How does the error compare with the first error?

2. Use the Runge-Kutta method to approximate y( 2 ) if y( 0 ) = 1 and y'( x ) = sin( 4x ). Let h = 0.05.

3. Use your own function f( x, y ) to define a separable differential equation that is not solvable using the usual integration methods. Define an initial value and approximate a final value by using the Runge-Kutta method. Show the table and the relevant graphs.