TOPIC 4 - Curve Fiiting and Interpolation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

NUMSOL-CE

▪ CURVE FITTING ▪ INTERPOLATION


ꟷ a procedure in which a mathematical formula ꟷ is a procedure for estimating a value between known
(equation) is used to best fit a given set of data points. values of data points.
▪ CURVE FITTING WITH A LINEAR EQUATION– Curve fitting using a linear equation (first degree
polynomial) is the process by which an equation of the form y = a1x + a0 is used to best fit given data
points.
LINEAR LEAST SQUARES REGRESSION
▪ a procedure in which the coefficients a1 and a0 of a linear function y = a1x + a0 are determined such that
the function has the best fit to a given set of data points. The best fit is defined as the smallest possible
total error that is calculated by adding the squares of the residuals.
▪ For a given set of n data points (xi, yi), the overall error calculated is:

▪ Since all the values xi and yi are known, E is a nonlinear function of the two variables a1 and a0. Taking
the partial derivatives and setting them equal to zero gives the values of a1 and a0 for minimum E:
LINEAR LEAST SQUARES REGRESSION

▪ Since the equations above contain summations that are the same, it is convenient to calculate the
summations first the substituting them in the equation:

▪ With the parameters above, the new equation for a1 and a0 are:
LINEAR LEAST SQUARES REGRESSION
Example: According to Charles's law for an ideal gas, at constant volume, a
linear relationship exists between the pressure, p, and temperature, T. In the
experiment shown in the figure, a fixed volume of gas in a sealed container is
submerged in ice water (T = 0°C). The temperature of the gas is then increased
in ten increments up to T = 100° C by heating the water, and the pressure of the
gas is measured at each temperature. The data from the experiment is:
T (oC) 0 10 20 30 40 50 60 70 80 90 100
P
0.94 0.96 1.0 1.05 1.07 1.09 1.14 1.17 1.21 1.24 1.28
(atm)

Use linear least-squares regression to determine a linear function in the form p =


a1T + a0 that best fits the data points. Calculate the coefficients by hand using
only the four data points: 0, 30, 70, and 100 °C.
LINEAR LEAST SQUARES REGRESSION
Use linear least-squares regression to determine a linear function in the form p = a1T + a0 that best fits
the data points. Calculate the coefficients by hand using only the four data points: 0, 30, 70, and 100 °C.
T (oC) 0 10 20 30 40 50 60 70 80 90 100
P
0.94 0.96 1.0 1.05 1.07 1.09 1.14 1.17 1.21 1.24 1.28
(atm)

Step 1: Get the coordinates of the data points.

(0 , 0.094) (30 , 1.05) (70 , 1.17) (100 , 1.28)

Step 2: Determine Sx ; Sxx ; Sxy ; and Sy


LINEAR LEAST SQUARES REGRESSION
Use linear least-squares regression to determine a linear function in the form p = a1T + a0 that best fits
the data points. Calculate the coefficients by hand using only the four data points: 0, 30, 70, and 100 °C.
T (oC) 0 10 20 30 40 50 60 70 80 90 100
P
0.94 0.96 1.0 1.05 1.07 1.09 1.14 1.17 1.21 1.24 1.28
(atm)

Step 2: Determine Sx ; Sxx ; Sxy ; and Sy

Sx = 0 + 30 + 70 + 100 = 200
Sxx = 02 + 302 + 702 + 1002 = 158000
Sxy = (0*0.94) + (30*1.05) + (70*1.17) + (100*1.28) = 241.4
Sy = 0.94 + 1.05 + 1.17 + 1.28 = 4.44
LINEAR LEAST SQUARES REGRESSION
Use linear least-squares regression to determine a linear function in the form p = a1T + a0 that best fits
the data points. Calculate the coefficients by hand using only the four data points: 0, 30, 70, and 100 °C.
T (oC) 0 10 20 30 40 50 60 70 80 90 100
P
0.94 0.96 1.0 1.05 1.07 1.09 1.14 1.17 1.21 1.24 1.28
(atm)

Step 3: Substitute: Sx = 200 ; Sxx = 158000 ; Sxy = 241.4 ; Sy = 4.44 to the equations
above.
LINEAR LEAST SQUARES REGRESSION
Use linear least-squares regression to determine a linear function in the form p = a1T + a0 that best fits
the data points. Calculate the coefficients by hand using only the four data points: 0, 30, 70, and 100 °C.
T (oC) 0 10 20 30 40 50 60 70 80 90 100
P
0.94 0.96 1.0 1.05 1.07 1.09 1.14 1.17 1.21 1.24 1.28
(atm)

Step 4: Substitute: a1 = 0.003345 and a0 = 0.9428 to the linear equation form p = a1T + a0
The equation that best fits the data is then defined by:

p = 0.003345T + 0.9428
LAGRANGE INTERPOLATING POLYNOMIALS – are a particular form of polynomials that can be
written to fit a given set of data points by using the values at the points. The polynomials can be written
right away and do not require any preliminary calculations for determining coefficients.

For two points, (x1, y1), and (x2, y2), the first-order Lagrange
polynomial that passes through the points has the form:
LAGRANGE INTERPOLATING POLYNOMIALS – are a particular form of polynomials that can be
written to fit a given set of data points by using the values at the points. The polynomials can be written
right away and do not require any preliminary calculations for determining coefficients.

For three points, (x1, y1), (x2, y2), and (x3, y3), the second-order
Lagrange polynomial that passes through the points has the
form:
LAGRANGE INTERPOLATING POLYNOMIALS – are a particular form of polynomials that can be
written to fit a given set of data points by using the values at the points. The polynomials can be written
right away and do not require any preliminary calculations for determining coefficients.

For n number of points, the n-1 order Lagrange polynomial that passes through n points (x1, y1),
(x2, y2), (x3, y3), … , (xn, yn) has the form:
LAGRANGE INTERPOLATING POLYNOMIALS
Example: The set of the following five data points is given:
x 1 2 4 5 7
y 52 5 -5 -40 10
(a) Determine the fourth-order polynomial in the Lagrange form that passes through the points.
(b) Use the polynomial obtained in part (a) to determine the interpolated value for x= 3.

(a) Following the form of Equation from the previous slide, the Lagrange Polynomial is:
LAGRANGE INTERPOLATING POLYNOMIALS
Example: The set of the following five data points is given:
x 1 2 4 5 7
y 52 5 -5 -40 10
(a) Determine the fourth-order polynomial in the Lagrange form that passes through the points.
(b) Use the polynomial obtained in part (a) to determine the interpolated value for x= 3.

(b) The interpolated value for x= 3 is obtained by substituting the x in the polynomial:
NEWTON’S INTERPOLATING POLYNOMIALS – a popular means of exactly fitting a given set of data
points. The general form of an n - 1 order Newton's polynomial that passes through n points is:

The special feature of this form of the polynomial is that the coefficients a1 through an can be determined
using a simple mathematical procedure.
Once the coefficients are known, the polynomial can be used for calculating an interpolated value at any
x.
For First – order Newton’s Polynomial:
NEWTON’S INTERPOLATING POLYNOMIALS – a popular means of exactly fitting a given set of data
points. The general form of an n - 1 order Newton's polynomial that passes through n points is:

For Second – order Newton’s Polynomial:


NEWTON’S INTERPOLATING POLYNOMIALS – a popular means of exactly fitting a given set of data
points. The general form of an n - 1 order Newton's polynomial that passes through n points is:

For Third – order Newton’s Polynomial:


NEWTON’S INTERPOLATING POLYNOMIALS
For n-1 – order Newton’s Polynomial:
NEWTON’S INTERPOLATING POLYNOMIALS
Example: The set of the following five data points is given:
x 1 2 4 5 7
y 52 5 -5 -40 10
(a) Determine the fourth-order polynomial in Newton’s form that passes through the points. Calculate the
coefficients by using a divided difference table.
(b) Use the polynomial obtained in part (a) to determine the interpolated value for x= 3.
(a) Newton’s polynomial form:

The coefficients can be determined by the divided difference table:


(a)The coefficients can be determined by the divided difference table:

The polynomial is then equivalent to:


(b) The interpolated value for x= 3 is:

You might also like