i i
“k” — 2011/11/22 — 10:14 — page 260 —
i i
260 NUMERICAL DIFFERENTIATION
EXAMPLE 9.4
Given f (x) = ex , use the MATLAB function diff to approximate f (1.5) with h = 0.1.
The approximation can be obtained in the following way:
>> x = [1.5 1.5+0.1];
>> y = exp(x);
>> dx = diff(x);
>> dy = diff(y);
>> format long
>> dy./dx
ans =
4.71343354057050
EXERCISE SET 9.1
1. Suppose a polynomial p2 interpolates f at xi , i = 0, 1, 2, where xi = a + ih.
By differentiating p2 , show that
f (x1 + h) − f (x1 − h)
p2 (x) = .
h2
2. Derive the following approximate formulas:
(a) f (x) ≈ 1
4h [f (x + 2h) − f (x − 2h)],
(b) f (x) ≈ 1
2h [4f (x + h) − 3f (x) − f (x + 2h)] .
3. Using Taylor’s series, derive the following approximation for the third deriva-
tive of f
1
f (x) ≈ [f (x + 2h) − 2f (x + h) + 2f (x − h) − f (x − 2h)] .
2h3
4. Using Taylor’s series, determine the error term for the approximate formula
1
f (x) ≈ [f (x + 2h) − f (x)] .
2h
5. Given f (x) = ex , approximate f (1) using the central-difference formula with
h = 0.1.
6. Using Taylor’s series, determine the error term for the approximate formula
1
f (x) ≈ [f (x + 4h) − f (x − h)] .
5h
i i
i
i i
“k” — 2011/11/22 — 10:14 — page 261 —
i i
NUMERICAL DIFFERENTIATION 261
7. Use Taylor’s series to derive the following approximation formula for the third
derivative of f .
1
f (x) ≈ [−f (x) + 3f (x + h) − 3f (x + 2h) + f (x + 3h)] .
h3
8. Use Taylor’s series to derive the following approximation formula for the first
derivative of f .
2f (x + 3h) − 9f (x + 2h) + 18f (x + h) − 11f (x)
f (x) ≈ .
6h
9. Show that the approximation formula in Exercise 8 has an error of O(h3 ).
10. What does the difference scheme approximates. Give its error order?
1
[f (x + 3h) + f (x − h) − 2f (x)].
2h
11. Derive a difference formula for f (x0 ) through f (x0 ), f (x0 −h), and f (x0 +2h)
and find the leading error term.
12. Show the approximation
8f (x + h) − 8f (x − h) − f (x + 2h) + f (x − 2h)
f (x) = .
12h
13. Compute the derivative of f (x) = sin x at π/3 using
(a) The forward-difference formula with h = 10−3 ,
(b) The central-difference formula with h = 10−3 ,
(c) The formula
f (x0 + αh) + (α2 − 1)f (x0 ) − α2 f (x0 − h)
f (x0 ) ≈
α(1 + α)h
with h = 10−3 and α = 0.5.
14. Using the following data find f (6.0) with error = O(h), and f (6.3), with
error = O(h2 )
x 6.0 6.1 6.2 6.3 6.4
f (x) 0.1750 −0.1998 −0.2223 −0.2422 −0.2596
15. Define
−f (x + 2h) + 4f (x + h) − 3f (x)
S(h) = .
2h
i i
i i