03.03.2014 Views

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

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.

Chapter 7<br />

Approximating Derivatives<br />

7.1 Finite Differences<br />

Suppose we have some blackbox function f(x) and we wish to calculate f ′ (x) at some given x. Not<br />

surprisingly, we start with Taylor’s theorem:<br />

f(x + h) = f(x) + f ′ (x)h + f ′′ (ξ)h 2<br />

.<br />

2<br />

Rearranging we get<br />

f ′ f(x + h) − f(x)<br />

(x) = − f ′′ (ξ)h<br />

.<br />

h<br />

2<br />

Remember that ξ is between x and x + h, but its exact value is not known. If we wish to calculate<br />

f ′ (x), we cannot evaluate f ′′ (ξ), so we approximate the derivative by dropping the last term. That<br />

is, we calculate [f(x + h) − f(x)] /h as an approximation 1 to f ′ (x). In so doing, we have dropped<br />

the last term. If there is a finite bound on f ′′ (z) on the interval in question then the dropped term<br />

is bounded by a constant times h. That is,<br />

f ′ (x) =<br />

f(x + h) − f(x)<br />

h<br />

+ O (h) (7.1)<br />

The error that we incur when we approximate f ′ (x) by calculating [f(x + h) − f(x)] /h is called<br />

truncation error. It has nothing to do with the kind of error that you get when you do calculations<br />

with a computer with limited precision; even if you worked in infinite precision, you would still<br />

have truncation error.<br />

The truncation error can be made small by making h small. However, as h gets smaller, precision<br />

will be lost in equation 7.1 due to subtractive cancellation. The error in calculation for small h<br />

is called roundoff error. Generally the roundoff error will increase as h decreases. Thus there is<br />

a nonzero h for which the sum of these two errors is minimized. See Example Problem 7.5 for an<br />

example of this.<br />

The truncation error for this approximation is O (h). We may want a more precise approximation.<br />

By now, you should know that any calculation starts with Taylor’s Theorem:<br />

f(x + h) = f(x) + f ′ (x)h + f ′′ (x)<br />

2<br />

f(x − h) = f(x) − f ′ (x)h + f ′′ (x)<br />

2<br />

h 2 + f ′′′ (ξ 1 )<br />

h 3<br />

3!<br />

h 2 − f ′′′ (ξ 2 )<br />

h 3<br />

3!<br />

1 This approximation for f ′ (x) should remind you of the definition of f ′ (x) as a limit.<br />

87

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

Saved successfully!

Ooh no, something went wrong!