Use Taylor series to show that the first derivative of a function f ( x ) at x 0
ID: 3792001 • Letter: U
Question
Use Taylor series to show that the first derivative of a function f ( x ) at x 0 can be approximated by: f ( x 0 ) [ f ( x 0 + h ) f ( x 0 h )]/ 2 h + O ( h 2 ) . The above formula is called the centered difference formula for the fi rst derivative. Then, if f ( x ) = e^x and x 0 = 1 / 2 write a MATLAB script which does the following: approximates the first derivative of f ( x ) given using the above formula and shows in a log-log plot the absolute error by halving h at each step, i.e., use h = 0 . 1, h = 0 . 05, h = 0 . 025 etc. Also, show that your approximation has O ( h 2 ) truncation error, i.e., the order of accuracy is 2. When your approximation starts gettin g worse and why does this happen? Hints: Note that if error Ch q where q is the order of accuracy, then log ( error ) log C + q log h . Therefore in the log-log plot, you must determine the slope of the straight line obtained therein which eventually is the valu e of q . Recall that for a straight line of the form of y = b + ax , two points can be selected on the x -axis, e.g., x 1 and x 2 and we can find the corresponding ordinates y 1 = y ( x 1 ) and y 2 = y ( x 2 ) . Then, we obtain the slope via a = y 2 y 1 x 2 x 1 .
Explanation / Answer
If the function f (x) can be evaluated at values that lie to the left and right of x, then the best two-point formula will involve abscissas that are chosen symmetrically on both sides of (Centered Formula of Order O(h2)). Assume that f C3[a, b] and that x
Furthermore, there exists a number c = c(x) [a, b] such that
(4) f(x)= f(x+h) f(xh)+Etrunc(f,h),
where
2h
Etrunc(f,h)=h2 f(3)(c) = Oh):
(5) f(x+h)= f(x)+ f (x)h+
and
(6) f(xh)= f(x) f (x)h+
After (6) is subtracted from (5), the result is
(7) f(x+h) f(xh)=2f (x)h+
(( f (3)(c1) + f (3)(c2))h3 3! .
f (2)(x)h2
2! +
f (2)(x)h2
2!
f (3)(c1)h3 3!
f (3)(c2)h3 3! .
Since f(3)(x) is continuous, the intermediate value theorem can be used to find a
value c so that
(8) f (3)(c1) + f (3)(c2) = f (3)(c).
2
This can be substituted into (7) and the terms rearranged to yield
f(x +h) f(x h) f(3)(c)h2 (9) f (x)= 2h 3!
The first term on the right side of (9) is the central-difference formula (3), the second term is the truncation error, and the proof is complete.
The calculation for h = 0.01 is
f(0.8) f(0.81)2f(0.80)+ f(0.79) 0.0001
0.689498433 2(0.696706709) + 0.703845316 0.0001
0.696690000.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.