Docsity

Approximating Derivatives: Taylor Series, Differences, and Extrapolation - Prof. Luke Olso, Study notes of Computer Science

Partial preview of the text

Download Approximating Derivatives: Taylor Series, Differences, and Extrapolation - Prof. Luke Olso and more Study notes Computer Science in PDF only on Docsity!

Lecture 15

Differentiation

L. Olson

Department of Computer Science University of Illinois at Urbana-Champaign

October 18, 2006

Goals

Previously, given data yi at node xi for i = 0 ,... , n, find a polynomial p(x) that approximates the function. That is, approximate a function f (x) with some function (polynomial) g(x) Now, try to approximate the derivative of f ′(x) Establish accuracy estimates

First attempt: Taylor

Taylor series:

f (z) = f (z 0 ) + (z − z 0 )f ′(z 0 ) +

(z − z 0 )^2 2

f ′′(ξ)

Then at z = x + h for z 0 = x we have

f (x + h) = f (x) + hf ′(x) +

h^2 2

f ′′(ξ)

Thus f ′(x) =

f (x + h) − f (x) h

h 2 f ′′(ξ)

Forward Difference

f ′(x) ≈

f (x + h) − f (x) h with error = −

h 2

f ′′(ξ) = O(h)

Numerical Test

Consider f (x) = sin(πx) on [− 1 , 1 ] Approximate f ′(x) = πcos(πx) with

f ′(x) ≈

f (x + h) − f (x) h

What is p for erri = |f ′(xi) − f (^) ∗′ (xi)| = chp? This says for two h’s h(k)^ and h(j)^ we

have

err(k)^ = c(h(k))p err(j)^ = c(h(j))p

So p =

log(err(k)/err(j)) log(h(k)/h(j))

Can we do better?

Look at the Taylor series Forward AND Backward together

f (x + h) = f (x) + hf ′(x) + h^2 2

f ′′(x) + h^3 6

f ′′′(x) + h^4 24

f ′′′′(ξ+)

f (x − h) = f (x) − hf ′(x) +

h^2 2

f ′′(x) −

h^3 6

f ′′′(x) +

h^4 24

f ′′′′(ξ−)

Subtract them:

f (x + h) − f (x − h) = 2 hf ′(x) + h^3 3

f ′′′(x) + O(h^4 )

Thus f ′(x) =

f (x + h) − f (x − h) 2 h

h^2 6 f ′′′(x) + O(h^3 )

Central Difference

f ′(x) =

f (x + h) − f (x − h) 2 h

h^2 6

f ′′′(x) + O(h^3 )

Central Difference

f ′(x) =

f (x + h) − f (x − h) 2 h

h^2 6 f ′′′(x) + O(h^3 )

with error = −

h^2 6

f ′′′(ξ) = O(h^2 )

Richardson Extrapolation

φ(h) = f ′(x) − c 2 h^2 − c 4 h^4 − c 6 h^6 −... φ(h/ 2 ) = f ′(x) − c 2 (h/ 2 )^2 − c 4 (h/ 2 )^4 − c 6 (h/ 2 )^6 −...

Combine these to elimintate the “c 2 ” term:

φ(h) − 4 φ(h/ 2 ) = − 3 f ′(x) − ( 3 / 4 )c 4 h^4 − ( 15 / 16 )c 6 h^6 −...

Dividing by -

φ(h/ 2 ) + ( 1 / 3 )(φ(h/ 2 ) − φ(h)) = f ′(x) + ( 1 / 4 )c 4 h^4 + ( 5 / 16 )c 6 h^6 −...

Fourth Order Richardson Extrapolation

f ′(x) = φ(h/ 2 ) + ( 1 / 3 )(φ(h/ 2 ) − φ(h)) + O(h^4 ) where φ(h) is the central difference approximation.

And better?

We can extend the Richard extrapolation idea to any order. Idea: use ψ(h) = φ(h/ 2 ) + ( 1 / 3 )(φ(h/ 2 ) − φ(h)) to annihilate the fourth order error term:

Fourth Order Richardson Extrapolation

f ′(x) = ψ(h/ 2 ) + ( 1 / 15 )(ψ(h/ 2 ) − ψ(h)) + O(h^6 )

where ψ(h) is the fourth order Richardson extrapolation.

Integrals

We seek a solution to the following quantity ∫ (^) b

a

f (x) dx

The Fundamental Theorem of Calculus states that ∫ (^) b

a

f (x) dx = F(b) − F(a)

where F is the antiderivative of f. We don’t know F, so we approximate the integral operation.

Integration

What is the integral

∫b a? Let P be a partition of [a, b] of n + 1 distinct and ordered points with x 0 = a and xn = b. For interval [xi, xi+ 1 ] let mi be a lower bound on f (x) For interval [xi, xi+ 1 ] let Mi be an upper bound on f (x) Lower Sum:

L(f ; P) =

n∑− 1

i= 0

mi(xi+ 1 − xi)

Upper Sum:

U(f ; P) =

∑^ n−^1

i= 0

Mi(xi+ 1 − xi)

Graphically: Integral

Graphically: lower sum

Left-Riemann, Right-Riemann, Mid-Point

The upper and lower bounds are often difficult to identify Use Left-Riemann, Right-Riemann, and Middle Riemann Sums Generally the Riemann sum is

S =

∑^ n−^1

i= 0

f (zi)(xi+ 1 − xi)

zi = xi is a Left Riemann Sum zi = xi+ 1 is a Right Riemann Sum zi = xi+^12 + xiis a Middle Riemann Sum