13
Part 5 Part 5 Chapter 19 Numerical Differentiation PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Part 5Part 5 Chapter 19 - University of Florida

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Part 5Part 5 Chapter 19 - University of Florida

Part 5Part 5Chapter 19

Numerical Differentiation

PowerPoints organized by Dr. Michael R. Gustafson II, Duke UniversityAll images copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Page 2: Part 5Part 5 Chapter 19 - University of Florida

Chapter Objectives• Understanding the application of high-accuracy numerical

differentiation formulas for equispaced datadifferentiation formulas for equispaced data.• Knowing how to evaluate derivatives for unequally spaced

data.U d t di h Ri h d t l ti i li d f• Understanding how Richardson extrapolation is applied for numerical differentiation.

• Recognizing the sensitivity of numerical differentiation to g g ydata error.

• Knowing how to evaluate derivatives in MATLAB with the diff and gradient functions.diff and gradient functions.

• Knowing how to generate contour plots and vector fields with MATLAB.

Page 3: Part 5Part 5 Chapter 19 - University of Florida

Differentiation• The mathematical definition of a derivative begins

ith diff i tiwith a difference approximation:y

f xi x f xi

and as x is allowed to approach zero, the difference becomes a derivative:

x x

dy

dx lim

x0

f xi x f xi x

Page 4: Part 5Part 5 Chapter 19 - University of Florida

High-Accuracy Differentiation FormulasFormulas

• Taylor series expansion can be used to generate high-accuracy formulas for derivatives by using linear algebra to combine the expansion around several points.

• Three categories for the formula include forward finite-difference, backward finite-difference, and centered finite-difference.

Page 5: Part 5Part 5 Chapter 19 - University of Florida

Forward Finite-Difference

Page 6: Part 5Part 5 Chapter 19 - University of Florida

Backward Finite-Difference

Page 7: Part 5Part 5 Chapter 19 - University of Florida

Centered Finite-Difference

Page 8: Part 5Part 5 Chapter 19 - University of Florida

Richardson Extrapolation• As with integration, the Richardson extrapolation can be used to

combine two lower-accuracy estimates of the derivative to produce a y phigher-accuracy estimate.

• For the cases where there are two O(h2) estimates and the interval is halved (h2=h1/2), an improved O(h4) estimate may be formed using:

• For the cases where there are two O(h4) estimates and the interval is

D 4

3D(h2 )

1

3D(h1)

For the cases where there are two O(h ) estimates and the interval is halved (h2=h1/2), an improved O(h6) estimate may be formed using:

D 16

15D(h2 )

1

15D(h1)

• For the cases where there are two O(h6) estimates and the interval is halved (h2=h1/2), an improved O(h8) estimate may be formed using:

15 15

64 1D

64

63D(h2 )

1

63D(h1)

Page 9: Part 5Part 5 Chapter 19 - University of Florida

Unequally Spaced Data

• One way to calculated derivatives of unequally spaced data is to determine a polynomial fit and take its derivative at a point.

• As an example, using a second-order p , gLagrange polynomial to fit three points and taking its derivative yields:g y

f x f x0 2x x1 x2

x0 x1 x0 x2 f x1 2x x0 x2

x1 x0 x1 x2 f x2 2x x0 x1

x2 x0 x2 x1 0 1 0 2 1 0 1 2 2 0 2 1

Page 10: Part 5Part 5 Chapter 19 - University of Florida

Derivatives and Integrals for Data with Errorswith Errors

• A shortcoming of numerical differentiation is that it tends to amplify errors in data whereas integration tends to smoothamplify errors in data, whereas integration tends to smooth data errors.

• One approach for taking derivatives of data with errors is to pp gfit a smooth, differentiable function to the data and take the derivative of the function.

Page 11: Part 5Part 5 Chapter 19 - University of Florida

Numerical Differentiation with MATLABMATLAB

• MATLAB has two built-in functions to help take derivatives, diff and gradient:

• diff(x)

– Returns the difference between adjacent elements in x

• diff(y)./diff(x)– Returns the difference between adjacent valuesReturns the difference between adjacent values

in y divided by the corresponding difference in adjacent values of x

Page 12: Part 5Part 5 Chapter 19 - University of Florida

Numerical Differentiation with MATLABMATLAB

• fx = gradient(f, h)Determines the derivative of the data in f at eachDetermines the derivative of the data in f at each of the points. The program uses forward difference for the first point, backward difference for the last ppoint, and centered difference for the interior points. h is the spacing between points; if omitted h=1.The major advantage of di t over diff is• The major advantage of gradient over diff is gradient’s result is the same size as the original data.

• Gradient can also be used to find partial derivatives for matrices:[ ] i ( h)[fx, fy] = gradient(f, h)

Page 13: Part 5Part 5 Chapter 19 - University of Florida

Visualization• MATLAB can generate contour plots of functions as

ll t fi ld A i d twell as vector fields. Assuming x and y represent a meshgrid of x and y values and z represents a function of x and yfunction of x and y, – contour(x, y, z) can be used to generate a contour

plotp– [fx, fy]=gradient(z,h) can be used to generate

partial derivatives andi ( f f ) b d t t– quiver(x, y, fx, fy) can be used to generate

vector fields