#### CS 3414 Homework 4 Due 5:00 p.m., June 20, 2002

1. As h goes to zero, finite difference formulas such as
```             x(t+h) - x(t)
x'(t) = -------------  + O(h)
h
```
and
```             x(t+h) - x(t-h)
x'(t) = ---------------  + O(h^2)
2h
```
are supposed to be better and better approximations to the derivative. However, in finite precision, the subtraction in the numerator of these expressions can cause problems (remember `cancellation error'?).

Write a simple program to observe this tradeoff --- the tradeoff between discretization error (which gets smaller as h goes to zero) and cancellation error (which gets larger). You do not have to turn in a copy of your program.

Try x(t) = t3 and evaluate the two finite difference formulas above for t=0.25. Try h = 10-n, for n = 1, 2, ..., 15. Give your results in a table something like this:

```           O(h) formula           O(h^2) formula
n    approx       relerr      approx     relerr
---------------------------------------------------
1  2.7250E-01  4.5333E-01  1.9750E-01  5.3333E-02
2  1.9510E-01  4.0533E-02  1.8760E-01  5.3333E-04
3  1.8825E-01  4.0053E-03  1.8750E-01  5.3333E-06

.
.
.

---------------------------------------------------
```

2. This problem is based on Problem Statement 4.

1. Use Euler's method to compute the velocity from time 0.0 to 2.0, using step size h = 0.1. Turn in a copy of your code and a table showing your computed v(t) at each time step.

2. Repeat part (a) but with a Taylor method that uses three terms of a Taylor series (one more than Euler's method uses).

3. Repeat part (a) but with a Runge-Kutta method of order 4.

4. For each of the three methods you implemented, determine how many evaluations of f(t,x) = g - kx|x|/m are needed to achieve 4 significant digits of accuracy in the solution at time t=2.0. The `correct' answer at t=2.0 is -5.485. You do not need to turn in any code for this problem; just give a table showing the number of function evaluations needed by each method. For the Taylor method, assume that an evaluation of f'(t,x) costs the same as an evaluation of f(t,x).