39
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3 : Interpolation and Curve Fitting Yarmouk University Computer Engineering Department

CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Embed Size (px)

Citation preview

Page 1: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

CpE- 310B Engineering Computation

and SimulationDr. Manal Al-Bzoor

Chapter 3 :Interpolation and Curve Fitting

Yarmouk University Computer Engineering Department

Page 2: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Interpolation Basic problem: for given data (set of points) (xi , yi), i=1,2,….,m

with x1 < x2 < … < xm determine the function f(xi) = yi, i=1,2,….,m

such that f is interpolating function, for the given data

Page 3: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Purposes of Interpolation

Plotting smooth curve through discrete data points

Reading between lines of table

Differentiating or integrating tabular data

Replacing complicated function by simple one

Page 4: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Interpolation vs Approximation

Interpolation function fits given data points exactly

Interpolation is inappropriate if data points subject to significant errors

Approximation is usually preferable for smoothing noisy data

Page 5: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Interpolating Functions Families of functions commonly used for interpolation include

PolynomialsPiecewise polynomialsTrigonometric functionsExponential functionsRational functions

We will focus on interpolation by polynomial and piecewise polynomials for now

Page 6: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Polynomial Interpolations Simplest type of interpolation usesPolynomials

Unique polynomial of degree at most n-1passes through n data points (xi yi), i = 1, …, n,where xi are distinct

There are many ways to represent or compute polynomial, but in theory all must give same result

Page 7: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Lagrangian PolynomialsExample

We choose 4 points for the third degree polynomial :

We need to find coefficients a, b, c, d

Can be found using previous chapter methods, by formulating 4 equations for a,b,c and d, using the points above

Page 8: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Lagrangian PolynomialsA simpler way is to use lagrangian Polynomials. For a cubic polynomial case,

4 points should be available, (x0,f0 ),(x1,f1),(x2,f2),(x3,f3)

The interpolating polynomial is then defined by

Page 9: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Lagrangian PolynomialsExampleFind the interpolated value for x = 3.0 using a cubic polynomial fitting the first 4 data points of the Table in previous slides

Page 10: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference Polynomial Need to re-compute the interpolation function if adding or removing a data point

Divided-differences method avoids this problem using fewer arithmetic operations

Divided-differences gives the same polynomial as Lagrangian interpolation

Page 11: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference Consider the Interpolating polynomial is written as:

If we choose ai so that Pn(x)=f(x) at the points (xi , fi ),i=0,…,n, then Pn(x) is an interpolating polynomial

ai ’s are determined by the divided differences of the tabulated data

Page 12: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference Given data points (xi, yi), I = 0,…,n, the divideddifferences, denoted by f[], is defined recursively by

Where

Page 13: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference Using the standard notations, the divided difference can be

Page 14: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference Example

Page 15: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided DifferenceIn the equation :

Lets write the polynomial equations with x=x0, x=x1, x=x2, …, x=xn, we get

Page 16: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference If Pn(x) is the interpolating polynomial , then it should match the table for all n+1 points

Page 17: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference

Pn(x) can be written now in terms of divided differences :

Page 18: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Difference Using the data obtained in the divided difference table

The interpolating polynomial of degree 3 is :

The degree 4 polynomial is found by adding one term to P3(x)

Page 19: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Divided Differences

ForThe divided difference table is

For an nth-degree polynomial, Pn(x), whose highest power term has the coefficient an, the nth divided differences will always be equal to an.

Page 20: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Error of Polynomial Interpolation Interpolation works better for x within xi ‘s

Error is smaller if x is centered within xi

The error term of polynomial interpolation is :

with ξ in the smallest interval that contains {x, ,x1 ,x2,…,xn }.

Not very useful for computing real error as f is usually unknown. If the function is "smooth," a low-degree polynomial should work satisfactorily.

Page 21: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Error Estimation: Next Term Rule

Error of the interpolates for f(1.75) using polynomials of degrees one, two, and three can be found by taking the derivatives and evaluating the minimum and maximum within an interval of the original function using:

Page 22: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Error Estimation: Next Term Rule

En(x) = (approximately) the value of the next term that would be

added to Pn(x).For the previous example

Page 23: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Evenly Spaced Data If data is given at evenly spaced intervals, arrange the date with the x values in ascending order. The difference table is then calculated “ without dividing by x difference” as

Page 24: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Evenly Spaced Data : difference table

Where :

Page 25: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Polynomial for Evenly Spaced Data

Newton-Gregory forward polynomial passes through equi_spaced points with an h distance between consecutive points

Where :

Page 26: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Polynomial for Evenly Spaced Data

Write a Newton-Gregory forward polynomial of degree 3 that fits for the four points at x = 0.4 to x = 1.0. Use it to interpolate for f(O. 73).

For the data in the difference table

To make the polynomial fit as specified, we must index the x's so that x0=4, it follows

Page 27: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Polynomial for Evenly Spaced Data

Page 28: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation Given a set of (x,y) data points,

Approximation is the process of finding a function (usually a line or a polynomial) that comes the “closest” to the data points.

Data has “noise” – cannot

find interpolating line.

Page 29: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation : Linear Data

Assume we have experimental data for the effect of temperature on resistance

The graph suggest a linear relationship

Page 30: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Linear Data

least Square criterion requires

The criterion used to find a and b is to minimize the sum of the squares of the errors, the "least-squares“ principleLet Yi represent an experimental value, and let yi be a value from the equation

yi= a xi + b,

Page 31: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation

To find the minimum of S, the partial derivatesShould be zero.

Reducing we get :

Page 32: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation For the Temperature data we have, Y is R and x is T

The normal equation are then

a = 3.395, b = 702.2,

Page 33: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Nonlinear Data

Nonlinear data can be fitted using exponential functions

Perform linearization by taking the logarithms

Rebuild the table to represent ln y and ln x instead of x and y

Page 34: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Nonlinear Data

Polynomial Approximation is the common method used to approximate nonlinear data . We assume the functional relationship to be :The error defined as

The sum of squares defined by S is

Page 35: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Polynomial approximation of nonlinear data

At the minimum all partial derivates should be zero

Page 36: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Polynomial approximation of nonlinear dataDividing each by -2 and rearranging gives the n + 1 normal equations to be solved simultaneously:

Page 37: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Polynomial approximation of nonlinear dataPutting the Previous Equation in Matrix Notation

Page 38: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Polynomial approximation of nonlinear dataUse quadratic polynomial to fit the data in the following table

We need to calculate the normal sums as follows

Page 39: CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor Chapter 3: Interpolation and Curve Fitting Yarmouk University Computer Engineering

Least Square Approximation: Polynomial approximation of nonlinear dataApplying these sums in the normal equations we get

Solving sets of equations for the coefficients we get

The least square polynomial is then