Docsity

Approximating Derivatives with Quotient, Chain, Centered Diff. & Lagrange Interpolation, Study notes of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
Jim Lambers
Math 105A
Summer Session I 2003-04
Lecture 11 Examples
These examples correspond to Section 4.1 in the text.
Example Consider the function
f(x) =
sin2√x2+x
cos x−x
sin √x−1
√x2+1 .
Our goal is to compute f0(0.25). Differentiating, using the Quotient Rule and the Chain Rule, we
obtain
f0(x) =
2 sin √x2+x
cos x−xcos √x2+x
cos x−xh 2x+1
2√x2+1(cos x−x)+√x2+1(sin x+1)
(cos x−x)2i
sin √x−1
√x2+1 −
sin √x2+x
cos x−xcos √x−1
√x2+1 h 1
2√x√x2+1 −x(√x−1)
(x2+1)3/2i
sin2√x−1
√x2+1 .
Evaluating this monstrous function at x= 0.25 yields f0(0.25) = −9.066698770.
An alternative approach is to use a centered difference approximation,
f0(x)≈f(x+h)−f(x−h)
2h.
Using this formula with x= 0.25 and h= 0.005, we obtain the approximation
f0(0.25) ≈f(0.255) −f(0.245)
0.01 =−9.067464295,
which has absolute error 7.7×10−4. While this complicated function must be evaluated twice to
obtain this approximation, that is still much less work than using differentiation rules to compute
f0(x), and then evaluating f0(x), which is much more complicated than f(x). 2
Example We will construct a formula for approximating f0(x) at a given point x0by interpolating
f(x) at the points x0,x0+h, and x0+ 2husing a second-degree polynomial p2(x), and then
approximating f0(x0) by p0
2(x0). Since p2(x) should be a good approximation of f(x) near x0,
especially when his small, its derivative should be a good approximation to f0(x) near this point.
Using Lagrange interpolation, we obtain
p2(x) = f(x0)L2,0(x) + f(x0+h)L2,1(x) + f(x0+ 2h)L2,2(x),
1
pf2

Partial preview of the text

Download Approximating Derivatives with Quotient, Chain, Centered Diff. & Lagrange Interpolation and more Study notes Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Jim Lambers Math 105A Summer Session I 2003- Lecture 11 Examples

These examples correspond to Section 4.1 in the text.

Example Consider the function

f (x) =

sin^2

x^2 +x cos x−x

sin

( (^) √x− 1 √x (^2) +

Our goal is to compute f ′(0.25). Differentiating, using the Quotient Rule and the Chain Rule, we obtain

f ′(x) =

2 sin

x^2 +x cos x−x

cos

x^2 +x cos x−x

) [

2 x+ 2 √x^2 +1(cos x−x) +

√x (^2) +1(sin x+1) (cos x−x)^2

]

sin

( (^) √x− 1 √x (^2) +

sin

x^2 +x cos x−x

cos

( (^) √x− 1 √x (^2) +

) [

1 2 √x√x^2 +1 −^

x(√x−1) (x^2 +1)^3 /^2

]

sin^2

( (^) √x− 1 √x (^2) +

Evaluating this monstrous function at x = 0.25 yields f ′(0.25) = − 9. 066698770. An alternative approach is to use a centered difference approximation,

f ′(x) ≈ f^ (x^ +^ h)^ −^ f^ (x^ −^ h) 2 h

Using this formula with x = 0.25 and h = 0.005, we obtain the approximation

f ′(0.25) ≈

f (0.255) − f (0.245)

  1. 01 =^ −^9.^067464295 ,

which has absolute error 7. 7 × 10 −^4. While this complicated function must be evaluated twice to obtain this approximation, that is still much less work than using differentiation rules to compute f ′(x), and then evaluating f ′(x), which is much more complicated than f (x). 2

Example We will construct a formula for approximating f ′(x) at a given point x 0 by interpolating f (x) at the points x 0 , x 0 + h, and x 0 + 2h using a second-degree polynomial p 2 (x), and then approximating f ′(x 0 ) by p′ 2 (x 0 ). Since p 2 (x) should be a good approximation of f (x) near x 0 , especially when h is small, its derivative should be a good approximation to f ′(x) near this point. Using Lagrange interpolation, we obtain

p 2 (x) = f (x 0 )L 2 , 0 (x) + f (x 0 + h)L 2 , 1 (x) + f (x 0 + 2h)L 2 , 2 (x),

1

where {L 2 ,j (x)}^2 j=0 are the Lagrange polynomials for the points x 0 , x 1 = x 0 + h and x 2 = x 0 + 2h. Recall that these polynomials satisfy

L 2 ,j (xk) = δjk =

1 if j = k 0 otherwise. Using the formula for the Lagrange polynomials,

L 2 ,j (x) =

∏^2

i=0,i 6 =j

(x − xi) (xj − xi) ,

we obtain

L 2 , 0 (x) = (x^ −^ (x^0 +^ h))(x^ −^ (x^0 + 2h)) (x 0 − (x 0 + h))(x 0 − (x 0 + 2h))

= x

(^2) − (2x 0 + 3h)x + (x 0 + h)(x 0 + 2h) 2 h^2 , L 2 , 1 (x) = (^) (x (x^ −^ x^0 )(x^ −^ (x^0 + 2h)) 0 +^ h^ −^ x 0 )(x 0 +^ h^ −^ (x 0 + 2h)) =

x^2 − (2x 0 + 2h)x + x 0 (x 0 + 2h) −h^2 , L 2 , 2 (x) =

(x − x 0 )(x − (x 0 + h)) (x 0 + 2h − x 0 )(x 0 + 2h − (x 0 + h))

= x

(^2) − (2x 0 + h)x + x 0 (x 0 + h) 2 h^2

It follows that

L′ 2 , 0 (x) = 2 x^ −^ (2x^0 + 3h) 2 h^2 L′ 2 , 1 (x) = − 2 x^ −^ (2x^0 + 2h) h^2 L′ 2 , 2 (x) = 2 x^ −^ (2x^0 +^ h) 2 h^2 We conclude that f ′(x 0 ) ≈ p′ 2 (x 0 ), where p′ 2 (x 0 ) = f (x 0 )L′ 2 , 0 (x 0 ) + f (x 0 + h)L′ 2 , 0 (x 0 ) + f (x 0 + 2h)L′ 2 , 0 (x 0 )

≈ f (x 0 )

2 h +^ f^ (x^0 +^ h)

h +^ f^ (x^0 + 2h)^

2 h ≈

3 f (x 0 ) + 4f (x 0 + h) − f (x 0 + 2h) 2 h. Using Taylor’s Theorem to write f (x 0 + h) and f (x 0 + 2h) in terms of Taylor polynomials centered at x 0 , it can be shown that the error in this approximation is O(h^2 ), and that this formula is exact when f (x) is a polynomial of degree 2 or less. 2