Professional Documents
Culture Documents
CE205 Interpolation Curvefitting
CE205 Interpolation Curvefitting
CE205 Interpolation Curvefitting
IInterpolation
t l ti and d
Curve fitting
Curve-fitting
Interpolation
‐for very precise data
‐ Ex: density of water at different temp.
Least‐squares Regression
‐for imprecise/noisy data
‐for imprecise/noisy data
‐ Purpose is trend analysis
Least‐square regression
q g
Visually sketch a line that conforms to the
data
Linear interpolation
Connect the data points consecutively by
Connect the data points consecutively by
lines segments
Polynomial interpolation
Connect the data points consecutively by
Connect the data points consecutively by
simple curves
Coefficients Residual Error
“Best” coefficients can be obtained by minimizing the sum
y g
of the squares of the estimate residuals.
n n
Sr = ∑ e = ∑ (yi − a0 − a1 xi )
2 2
i
i=1 i=1
n∑ xi yi − ∑ xi ∑ yi
a1 =
n∑ x − (∑ x )
2
2
i i
a0 = y − a1 x
Sr
St d d
Standard error of the estimate:
f th ti t s y/ x =
n−2
(a) the spread of data around the (b) the spread of the data around
mean of the dependent data the best fit line:
Sum of squares of residuals Sum of squares of residuals between
between data points and the mean data points and the regression line
n
S r = ∑ ( yi − a0 − a1 xi )
n
S t = ∑ ( yi − y )
2 2
i =1 i =1
St‐Sr quantifies the improvement or error reduction due to
describing data in terms of a straight line rather than as an
average value
St − Sr
r =
2
St
r2 represents the percentage of the original uncertainty
explained by the model (Coefficient of Determination)
‐ For a perfect fit, S
F 0 d 2=1.
f t fit Sr=0 and r 1
‐ If r2=0, there is no improvement over simply picking the mean.
‐ If r2<0, the model is worse than simply picking the mean!
Some engineering data is
Some engineering data is
poorly represented by a
straight line
straight line.
A higher order polynomial
A higher order polynomial
(e.g. parabola) may be well‐
suited
suited
The coefficients can be determined using Gaussian
elimination:
The sum of squares of residuals:
n n
Sr = ∑ e = ∑ (yi − a0 − a1 xi − a x −L− a x
2
i
2
2 i m i )
m 2
i=1 i=1
Can you formulate the matrix to determine the
coefficients?
ff
y is a linear function of two or
more independent variables:
y = a0 + a1 x1 + a2 x2 +Lam xm
Again, the best fit is obtained
y g
by minimizing the sum of the
squares of the estimate
residuals:
n n
Sr = ∑ e = ∑ (yi − a0 − a1 x1,i − a2 x2,i −Lam xm,i )
2 2
i
i 1
i=1 i 1
i=1
Three common examples are:
power : y = α 2 x β2
x
saturation - growth - rate : y = α 3
β3 + x
this may involve taking logarithms or inversion:
exponential : y = α1eβ1 x ln y = ln α1 + β1 x
there is one and only one nth‐order polynomial that fits
n+1
n 1 points
points
f ( x) = a1 + a2 x + a3 x 2 + L + an x n −1
First order:
Fi t d
The first‐order Newton
i t
interpolating polynomial
l ti l i l
may be obtained from
li
linear interpolation and
i t l ti d
similar triangles
f (x2 ) − f (x1 )
f1 (x) = f (x1 ) + (x − x1 )
x2 − x1
Values of coefficients can be obtained by a
simple procedure:
b0 = f ((xx0 )
f ( x1 ) − f ( x0 )
b1 =
x1 − x0
f ( x2 ) − f ( x1 ) f ( x1 ) − f ( x0 )
−
x2 − x1 x1 − x0
b2 =
x2 − x0
CE 205: Numerical Methods Dr. Tanvir Ahmed
Newton’s interpolating polynomials
General form:
n‐th order polynomial to fit n+1 data points
p y p
f n ( x ) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 ) + ..... + bn ( x − x0 )( x − x1 )...( x − xn −1 )
b0 = f ( x0 )
b1 = f [x1 , x0 ]
b2 = f [x2 , x1 , x0 ]
M
bn = f [xn , xn −1 , L , x1 , x0 ]
f[….] represent divided differences
f1 ( x) = L1 f ( x1 ) + L2 f ( x2 )
x − x2 x − x1
L1 = , L2 =
x1 − x2 x2 − x1
x − x2 x − x1
f1 ( x) = f ( x1 ) + f ( x2 )
x1 − x2 x2 − x1
General form:
The Lagrange interpolating polynomial for n points
n
fn−1 (xi ) = ∑ Li (x ) f (xi )
i=1
x − xj
n
Li (x) = ∏
x − xj
j=1 i
j≠i
the process of estimating a
p g
value of f(x) that lies
g
outside the range of the
known base points.
Extrapolation represents a
step into the unknown
step into the unknown,
and extreme care should
be exercised when
be exercised when
extrapolating!
Higher order polynomials tend to overshoot the trend
of the data
of the data
CE 205: Numerical Methods Dr. Tanvir Ahmed
Hazards of higher order polynomials
A seventh order population dataset
Diffi lt t f t l ti
‐Difficult to use for extrapolation
Can also introduce oscillations to an interpolation or
Can also introduce oscillations to an interpolation or
fit where they should not be.
Splines eliminate oscillations by using
small subsets of points for each interval
ll b f i f hi l
rather than every point. This is especially
useful when there are jumps in the data:
useful when there are jumps in the data:
Second‐order splines
‐ Quadratic equations between each pair of
points
points
‐ Go through the points
‐ Match first derivatives at the interior points
Third‐order splines
‐ Cubic equations between each pair of points
q p p
‐ Go through the points
‐Match first and second derivatives at the
interior points
‐Different from cubic interpolating polynomial
(n+1) datapoints → n intervals → 3n unknowns
→ 3n conditions required
The general form of the i‐th spline:
f i ( x ) = ai x 3 + bi x 2 + ci x + d i
(n+1) datapoints
(n+1) datapoints → n intervals → 4n unknowns
→ n intervals → 4n unknowns
→ 4n conditions required
Clamped end conditions
‐ the first derivatives at the first and last knots are known.
“Not‐a‐knot” end conditions
‐ force continuity of the third
force continuity of the third derivative at the second and penultimate points
derivative at the second and penultimate points
“Not‐a‐knot” end conditions Clamped end conditions