Math 227 Final Computer Lab

1. Go to this website, run dfield and try to print. If you can't get it to print, click on the link to download the dfield program for Matlab. Use the program to understand the behavior of textbook section 11.4 problems 1a, 1b, 1c, 1e. Make printouts for each one with a few representative trajectories on each.

2. I wrote a short implementation of the Euler method for numerically solving an ordinary differential equation: easyEuler.m

Here's an example of how to use it: first create an m-file with a top line:

function yprime=f(t,y)

I am running this with the file exampleODE.m from t0=0 to t1=2 with initial condition y0=1 and stepsize h=0.1

t0=0;t1=2;
y0=1;
h=0.1;
[t,y]=easyEuler(@exampleODE,t0,t1,y0,h);
plot(t,y);xlabel('t');ylabel('y(t)');title('Simulation with Euler method')
  i  t(i)     y_i   
---------------------
  0  0.00  1.0000000
  1  0.10  1.4000000
  2  0.20  1.7600000
  3  0.30  2.0840000
  4  0.40  2.3756000
  5  0.50  2.6380400
  6  0.60  2.8742360
  7  0.70  3.0868124
  8  0.80  3.2781312
  9  0.90  3.4503180
 10  1.00  3.6052862
 11  1.10  3.7447576
 12  1.20  3.8702819
 13  1.30  3.9832537
 14  1.40  4.0849283
 15  1.50  4.1764355
 16  1.60  4.2587919
 17  1.70  4.3329127
 18  1.80  4.3996215
 19  1.90  4.4596593
 20  2.00  4.5136934

Download the program and use it to solve the ordinary

$$ \frac{dy}{dx} = \frac{y+x^2-2}{x+1}. $$

with initial condition $y(0)=1$ from $x=0$ to $x=5$. Use a step size of $\Delta x = 0.1$ and $\Delta x = 0.05$.

This has exact solution:

$$ y(x)= x^2 +  x + 1 - 2(x+1) \ln{(x+1)}.$$

Make two plots. On the first, show the exact solution and the two numerical approximations. On the second show the error in each method to show that the error is half as large with the smaller $\Delta x$.

3. A better method is called the fourth-order Runge-Kutta method, download my code easyRungeKutta.m and repeat problem 2. By what factor does the error go down now?