Professional Documents
Culture Documents
1) - Numerical Differentiation
Approximation error: Consider the Taylor polynomials and remainder of fx h and fx − h;
′ ′′
f x f c 2
fx h fx h h where c is in x, x h ;
1! 2!
′ ′′
f x f c 2
fx − h fx − h h where c is in x − h, x .
1! 2!
Then
′′
′ fx h − fx f c fx h − fx
f x − h Oh
h 2! h
′′
′ fx − fx − h f c fx − fx − h
f x h Oh
h 2! h
Approximation errors for the forward difference and the backward difference formulas are
′′
′ fx h − fx f c
R fd f x − − h , where c is in x, x h .
h 2!
′′
′ fx − fx − h f c
R bd f x − h , where c is in x − h, x .
h 2!
Now consider
′ ′′ ′′′
f x f x 2 f c 1 3
fx h fx h h h
1! 2! 3!
′ ′′ ′′′
f x f x 2 f c 2 3
fx − h fx − h h − h
1! 2! 3!
′′′ ′′′
′ f 1 x f c 2
fx h − fx − h 2hf x h3
3! 3!
1
′′′ ′′′ ′′′
′ fx h − fx − h f c 1 f c 2 fx h − fx − h 2f c
f x − 1 h
3
− 1 h2
2h 2h 3! 3! 2h 2 3!
′′′
fx h − fx − h f c 2 fx h − fx − h
− h Oh 2
2h 3! 2h
Approximation errors for the central difference formula is
′′′
′ fx h − fx − h f c 2
R cd f x − − h where c is in x − h, x h .
2h 6
′′
b. Difference formula for f and its approximation error:
′′
Derive a difference formula for f x :
′ ′′ ′′′
f x f x 2 f x 3 f 4 c 1 4
fx h fx h h h h
1! 2! 3! 4!
′ ′′ ′′′
f x f x 2 f x 3 f 4 c 2 4
fx − h fx − h h − h h
1! 2! 3! 4!
′′
fx h fx − h 2fx f xh 2 1 f 4 c 1 f 4 c 2 h 4
4!
′′ fx h − 2fx fx − h 2
f x 2
− h f 4 c 1 f 4 c 2 , c 1 is in x, x h , c 2 is in x − h, x
h 4!
fx h − 2fx fx − h
− 2 f 4 ch 2
h2 4!
(f 4 c 1 f 4 c 1 f 4 c 2 , cx is in x − h, x h )
2
fx h − 2fx fx − h
− 1 f 4 cxh 2
h2 12
y 12
10
4
Graphically,
2
-1 1 2 3
-2
x
-4
2
′
c. Difference formulas for f x :
#
Formula approx c
of
error
pts
′′
1 fx h − fx f c
2-1 − h x, x h
h 2!
′′
1 fx − fx − h f c
2-2 − h x − h, x
h 2!
′′′
1 1 fx h − 1 fx − h f c 2
3-1 − h x − h, x h
h 2 2 6
′′′
1 − 3 fx 2fx h − 1 fx 2h f c 2
3-2 h x, x 2h
h 2 2 3
′′′
1 1 fx − 2h − 2fx − h 3 fx f c 2
3-3 h x − 2h, x
h 2 2 3
5
1 1 fx − 2h − 8 fx − h 8 fx h − 1 fx 2h f c 4
5-1 h x − 2h, x 2h
h 12 12 12 12 30
5
1 − 25 fx 48 fx h − 36 fx 2h 16 fx 3h − 3 fx 4h f c 4
5-2 h x, x 4h
h 12 12 12 12 12 5
′′
Difference formula for f x :
# of pts Formula approx error c
1 fx h − 2fx fx − h f 4 c 2
3-1 − h x − h, x h
h2 12
3
1. Example Let fx sine x − 1.
′
i. Approximate f 0 by all three difference formulas with h 0. 1, and 0. 01, and compute an upper
bound for each approximation error and compute the true error.
′′
ii. Approximate f 0 with h 0. 1 and 0. 01, and find an upper bound for the approximation error and
compare it with the true error.
′ ′
i. f x e x cose x − 1, f 0 1
fx 0 h − fx 0 sine h − 1 − sine 0 − 1 sine h − 1
h h h
fx 0 − fx 0 − h 0 − sine −h − 1 − sine −h − 1
h h h
fx 0 h − fx 0 − h sine h − 1 − sine −h − 1
2h 2h
′′ ′′
f x e x cose x − 1 − e 2x sine x − 1, f 0 1
′′′
f x e x cose x − 1 − 3e 2x sine x − 1 − e 3x cose x − 1
y
1.00 y 0.6
0.99 0.4
0.98 0.2
4
− sine −h − 1 sine −h − 1
h Approximation true error 1 approx. error ≤ h
h h 2
− sine −0.1 − 1 sine −0.1 − 1 0. 1 0. 05
0. 1 0. 950 19 1 4. 981 0 10 −2
0. 1 0. 1 2
− sine −0.01 − 1 sine −0.01 − 1 0. 01 0. 005
0. 01 0. 995 1 4. 999 8 10 −3
0. 01 0. 01 2
Central difference:
0. 1 2 0.1
h 0. 1, R cd |e − e 30.1 cose 0.1 − 1 − 3e 20.1 sine 0.1 − 1| 1. 046 656 699 10 −3
6
0. 01 2 0.01
h 0. 01, R cd |e − e 30.01 cose 0.01 − 1 − 3e 20.01 sine 0.01 − 1| 8. 527 066 727 10 −7
6
approx. error
Approximation true error 2
h sine h − 1 − sine −h − 1 | h e h − e 3h cose h − 1
sine h − 1 − sine −h − 1 1− 6
2h 2
2h − h 3e 2h sine h − 1|
6
sine 0.1 − 1 − sine −0.1 − 1 sine 0.1 − 1 − sine −0.1 − 1
1−
0. 1 20. 1 20. 1 1. 046 656 699 10 −3
0. 999 98 1. 919 851 521 10 −5
sine 0.1 −1sine −0.1 −1 sine 0.1 −1sine −0.1 −1
1−
0. 1 0.1 2
0.1 2 6. 413 554 783 10 −3
0. 995 812 780 8 4. 187 219 244 10 −3
e 0.01 sine 0.01 −1e −0.01 sine −0.01 −1 sine 0.01 −1sine −0.01 −1
1−
0. 01 0.01 2
0.01 2 4. 361 439 006 10 −5
0. 999 999 998 1 4. 166 872 222 10 −5
Note that
n
R
′
n x m 1
n 1!
f n1 cx x m − x i .
i0, i≠m
Difference Formulas:
n 2, 3 points: x 0 , x 1 , x 2 . Let h 0 and x 1 x 0 h, and x 2 x 1 h x 0 2h.
7
P 2 x fx 0 L 2,0 x fx 1 L 2,1 x fx 2 L 2,2 x,
P ′2 x fx 0 L ′2,0 x fx 1 L ′2,1 x fx 3 L ′2,2 x.
x − x 1 x − x 2
L ′2,0 x d 1 x − x 2 x − x 1
dx x 0 − x 1 x 0 − x 2 x 0 − x 1 x 0 − x 2
L ′2,1 x 1 x − x 0 x − x 2
x 1 − x 0 x 1 − x 2
L ′2,2 x 1 x − x 0 x − x 1
x 2 − x 0 x 2 − x 1
x − x 2 x − x 1 x − x 0 x − x 2 x − x 0 x − x 2
P ′2 x fx 0 fx 1 fx 2
x 0 − x 1 x 0 − x 2 x 1 − x 0 x 1 − x 2 x 2 − x 0 x 2 − x 1
fx 0 fx 1 fx 2
x − x 2 x − x 1 − 2
x − x 0 x − x 2 x − x 0 x − x 2
h2 h h2
fx 0 fx 1 fx 2
P ′2 x 0 2
−2h −h − 2
−2h −h
2h h 2h 2
1 − 3 fx 0 2fx 0 h − 1 fx 0 2h
h 2 2
′′′ ′′′
R ′ x 0 1 f cx−h−2h 1 h 2 f cx
3! 3
f x 0 h 1 −1 fx 0 1 fx 0 2h − 1 h 2 f cx
′ ′′′
h 2 2 3
′ ′′′
f x 0 2h 1 1 fx 0 − 2fx 1 3 fx 0 2h 1 h 2 f cx
h 2 2 3
′′′
Approximation errors are all Oh 2 if f x is bounded.
Exercises:
′ fx 0 − fx 0 − h
1. (1) Use the backward difference formula: f x 0 ≈ to approximate the derivative
2h
fx sinx at x 0 using h 0. 1, h 0. 01 and h 0. 001.
(2) Compute the true error and an upper bound on the approximation error for each h.
(1) x 1 2 3 4 5 ;
fx 2. 4142 2. 6734 2. 8974 3. 0976 3. 2804
′ ′′ ′′′ 4 5
(2) for x in 1, 5, f x ≤ 2, f x ≤ 3, f x ≤ 4, f x ≤ 12, f x ≤ 23.
′
a. Approximate f 3 by
(1) an approximation using two points;
(2) an approximation using three points; and
(3) an approximation using five points..
b. Which formula you used in a. is the best? Provide fully explanation to support your answer.
8
′ fx 0 2h − fx 0 − h
f x 0 ≈ .
3h
(2) Derive the error term associated with this formula.
(3) Consider fx lnx and x 0 2. Approximate f ′ 2 numerically by (1) with h 0. 1 and h 0. 01 and
estimate the approximation error using the error term obtained in (2) for each h.
6. Verify that each of the following difference approximations for the first derivative provides the exact value of
the derivative, regardless of h, for functions fx 1, fx x, and fx x 2 but not for the function
fx x 3 .
′ −3fx 0 4fx 0 h − fx 0 2h
(1) f x 0 ≈
2h
′ 3fx 0 − 4fx 0 − h fx 0 − 2h
(2) f x 0 ≈
2h
′ fx 0 h − fx 0 − h
(3) f x 0 ≈
2h