Holooly Plus Logo

Question 8.6: Comparing numerical and analytical differentiation. Consider......

Comparing numerical and analytical differentiation.

Consider the function f(x)=e^{x}. Write an expression for the first derivative of the function at x = 0 using the two-point central difference formula in Eq. (8.20).

f^{\prime}\left(x_i\right)=\frac{f\left(x_{i+1}\right)- f\left(x_{i-1}\right)}{2h}+O\left(h^2\right)          (8.20)

Investigate the effect that the spacing, h, between the points has on the truncation and round-off errors.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

The two-point central difference formula in Eq. (8.20) is:

f^{\prime}\left(x_{i}\right)=\frac{f\left(x_{i+1}\right)-f\left(x_{i-1}\right)}{2 h}-2 \frac{f^{\prime \prime \prime}(\xi)}{3 !} h^{2}

where ξ is a value of x between x_{i-1} and x_{i+1}

The points used for calculating the derivative of f(x)=e^{x} at x = 0 are x_{i-1}=-h and x_{i+1}=h. Substituting these points in the formula gives:

f^{\prime}(0)=\frac{e^{h}-e^{-h}}{2 h}-2 \frac{f^{\prime \prime \prime}(\xi)}{3 !} h^{2}            (8.55)

When the computer calculates the values of e^{h} and e^{-h}, a round-off error is introduced, since the computer has finite precision. Consequently, the terms e^{h} and e^{-h} in Eq. (8.55) are replaced by e^{h}+R_{1} and e^{-h}+R_{2} where now e^{h} and e^{-h} are the exact values, and R_{1} and R_{2} are the round-off errors:

f^{\prime}(0)=\frac{e^{h}+R_{1}-e^{-h}-R_{2}}{2 h}-2 \frac{f^{\prime \prime \prime}(\xi)}{3 !} h^{2}=\frac{e^{h}-e^{-h}}{2 h}+\frac{R_{1}-R_{2}}{2 h}-2 \frac{f^{\prime \prime \prime}(\xi)}{3 !} h^{2}          (8.56)

In Eq. (8.56) the last term on the right-hand side is the truncation error. In this term, the value of f ”'(ξ) is not known, but it is bounded. This means that as h decreases the truncation error decreases.

The round-off error is \left(R_{1}-R_{2}\right) /(2 h). As h decreases the roundoff error increases. The total error is the sum of the truncation error and round-off error. Its behavior is shown schematically in the figure on the right. As h decreases, the total error initially decreases, but after a certain value (which depends on the precision of the computer used) the total error increases as h decreases further.

8.6

Related Answered Questions