



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Jim Lambers MAT 460/ Fall Semester 2009- Lecture 23 Notes
These notes correspond to Section 4.1 in the text.
We now discuss the other fundamental problem from calculus that frequently arises in scientific applications, the problem of computing the derivative of a given function 푓 (푥).
Recall that the derivative of 푓 (푥) at a point 푥 0 , denoted 푓 ′(푥 0 ), is defined by
푓 ′(푥 0 ) = lim ℎ→ 0
This definition suggests a method for approximating 푓 ′(푥 0 ). If we choose ℎ to be a small positive constant, then
푓 ′(푥 0 ) ≈
This approximation is called the forward difference formula. To estimate the accuracy of this approximation, we note that if 푓 ′′(푥) exists on [푥 0 , 푥 0 + ℎ], then, by Taylor’s Theorem, 푓 (푥 0 + ℎ) = 푓 (푥 0 ) + 푓 ′(푥 0 )ℎ + 푓 ′′(휉)ℎ^2 / 2 , where 휉 ∈ [푥 0 , 푥 0 + ℎ]. Solving for 푓 ′(푥 0 ), we obtain
푓 ′(푥 0 ) =
so the error in the forward difference formula is 푂(ℎ). We say that this formula is first-order accurate. The forward-difference formula is called a finite difference approximation to 푓 ′(푥 0 ), because it approximates 푓 ′(푥) using values of 푓 (푥) at points that have a small, but finite, distance between them, as opposed to the definition of the derivative, that takes a limit and therefore computes the derivative using an “infinitely small” value of ℎ. The forward-difference formula, however, is just one example of a finite difference approximation. If we replace ℎ by −ℎ in the forward-difference formula, where ℎ is still positive, we obtain the backward-difference formula
Like the forward-difference formula, the backward difference formula is first-order accurate.
If we average these two approximations, we obtain the centered-difference formula
To determine the accuracy of this approximation, we assume that 푓 ′′′(푥) exists on the interval [푥 0 − ℎ, 푥 0 + ℎ], and then apply Taylor’s Theorem again to obtain
where 휉+ ∈ [푥 0 , 푥 0 + ℎ] and 휉− ∈ [푥 0 − ℎ, 푥 0 ]. Subtracting the second equation from the first and solving for 푓 ′(푥 0 ) yields
By the Intermediate Value Theorem, 푓 ′′′(푥) must assume every value between 푓 ′′′(휉−) and 푓 ′′′(휉+) on the interval (휉−, 휉+), including the average of these two values. Therefore, we can simplify this equation to
푓 ′(푥 0 ) =
where 휉 ∈ [푥 0 −ℎ, 푥 0 +ℎ]. We conclude that the centered-difference formula is second-order accurate. This is due to the cancellation of the terms involving 푓 ′′(푥 0 ).
Example Consider the function
푓 (푥) =
sin^2
푥^2 +푥 cos 푥−푥
sin
√푥−^1 푥^2 +
Our goal is to compute 푓 ′(0.25). Differentiating, using the Quotient Rule and the Chain Rule, we obtain
2 sin
푥^2 +푥 cos 푥−푥
cos
푥^2 +푥 cos 푥−푥
h 2 푥+ 2 √푥^2 +1(cos 푥−푥) +
√ 푥^2 +1(sin 푥+1) (cos 푥−푥)^2
i
sin
√푥−^1 푥^2 +
sin
푥^2 +푥 cos 푥−푥
cos
√푥−^1 푥^2 +
h 1 2 √푥 √ 푥^2 +1 −^
푥(√푥−1) (푥^2 +1)^3 /^2
i
sin^2
√푥−^1 푥^2 +
Evaluating this monstrous function at 푥 = 0.25 yields 푓 ′(0.25) = − 9. 066698770.
which is fourth-order accurate. The reason it is called a five-point formula, even though it uses the value of 푓 (푥) at four points, is that it is derived from the Lagrange polynomials for the five points 푥 0 − 2 ℎ, 푥 0 − ℎ, 푥 0 , 푥 0 + ℎ, and 푥 0 + 2ℎ. However, 푓 (푥 0 ) is not used in the formula because ℒ′ 4 , 0 (푥 0 ) = 0, where ℒ 4 , 0 (푥) is the Lagrange polynomial that is equal to one at 푥 0 and zero at the other four points. If we do not have any information about 푓 (푥) for 푥 < 푥 0 , then we can use the following five-point formula that actually uses the values of 푓 (푥) at five points,
where 휉 ∈ [푥 0 , 푥 0 + 4ℎ]. As before, we can replace ℎ by −ℎ to obtain a similar formula that approximates 푓 ′(푥 0 ) using the values of 푓 (푥) at 푥 0 , 푥 0 − ℎ, 푥 0 − 2 ℎ, 푥 0 − 3 ℎ, and 푥 0 − 4 ℎ. The strategy of differentiating Lagrange polynomials to approximate derivatives can be used to approximate higher-order derivatives. For example, the second derivative can be approximated using a centered difference formula,
푓 ′′(푥 0 ) ≈
which is second-order accurate.
Example We will construct a formula for approximating 푓 ′(푥) at a given point 푥 0 by interpolating 푓 (푥) at the points 푥 0 , 푥 0 + ℎ, and 푥 0 + 2ℎ using a second-degree polynomial 푝 2 (푥), and then approximating 푓 ′(푥 0 ) by 푝′ 2 (푥 0 ). Since 푝 2 (푥) should be a good approximation of 푓 (푥) near 푥 0 , especially when ℎ is small, its derivative should be a good approximation to 푓 ′(푥) near this point. Using Lagrange interpolation, we obtain
푝 2 (푥) = 푓 (푥 0 )ℒ 2 , 0 (푥) + 푓 (푥 0 + ℎ)ℒ 2 , 1 (푥) + 푓 (푥 0 + 2ℎ)ℒ 2 , 2 (푥),
where {ℒ 2 ,푗 (푥)}^2 푗=0 are the Lagrange polynomials for the points 푥 0 , 푥 1 = 푥 0 + ℎ and 푥 2 = 푥 0 + 2ℎ. Recall that these polynomials satisfy
ℒ 2 ,푗 (푥푘) = 훿푗푘 =
1 if 푗 = 푘 0 otherwise
Using the formula for the Lagrange polynomials,
푖=0,푖∕ =푗
we obtain
ℒ 2 , 0 (푥) =
It follows that
ℒ′ 2 , 0 (푥) =
We conclude that 푓 ′(푥 0 ) ≈ 푝′ 2 (푥 0 ), where 푝′ 2 (푥 0 ) = 푓 (푥 0 )ℒ′ 2 , 0 (푥 0 ) + 푓 (푥 0 + ℎ)ℒ′ 2 , 0 (푥 0 ) + 푓 (푥 0 + 2ℎ)ℒ′ 2 , 0 (푥 0 )
≈ 푓 (푥 0 )
Using Taylor’s Theorem to write 푓 (푥 0 + ℎ) and 푓 (푥 0 + 2ℎ) in terms of Taylor polynomials centered at 푥 0 , it can be shown that the error in this approximation is 푂(ℎ^2 ), and that this formula is exact when 푓 (푥) is a polynomial of degree 2 or less. □
In a practical implementation of finite difference formulas, it is essential to note that roundoff error in evaluating 푓 (푥) is bounded independently of the spacing ℎ between points at which 푓 (푥) is evaluated. It follows that the roundoff error in the approximation of 푓 ′(푥) actually increases as ℎ decreases, because the errors incurred by evaluating 푓 (푥) are divided by ℎ. Therefore, one must choose ℎ sufficiently small so that the finite difference formula can produce an accurate approximation, and sufficiently large so that this approximation is not too contaminated by roundoff error.
If the function 푓 (푥) can be represented as a sequence of computations, each consisting of the evaluation of some differentiable function with differentiable arguments, then a similar sequence of