Function Approximation, Interpolation, and Curve Fitting PDF
Function Approximation, Interpolation, and Curve Fitting PDF
Function Approximation, Interpolation, and Curve Fitting PDF
f(x) ≈ pn(x)
For example,
2 3 4
x x x
ex =1+ x + + + +!
2! 3! 4!
Taylor Polynomial Approximation
If f ∈ Cn+1[a,b] and x0 ∈ Cn+1[a,b] is a fixed value,
then
f (x ) ≈ p n (x )
Where
n (k )
p n (x ) =
f (x0 ) (x − x )k
∑
k =0 k!
0
• Lagrange interpolation
• Newton interpolation
p2 (x ) = L0 (x ) ⋅ f 0 + L1 (x ) ⋅ f1 + L2 (x ) ⋅ f 2
1.0 1.0
Example 3
Construct P2(x) for the data points (0, -1),
(1, -1), and (2, 7).
Solution:
P2 ( x ) = (−1)
( x −1) ( x − 2) + x ( x − 2) x ( x −1)
(−1) + ( 7)
2 −1 2
Lagrange Interpolation
In general, the nth degree Lagrange
interpolation polynomial may be written
as n
f (x ) ≈ p n (x ) = ∑ Lk (x ) ⋅ f k
k =0
where
L (x ) = ∏
(x−x )
n
j
k
(x − x )
j =0, j ≠ k k j
Newton Polynomials
• It is sometimes useful to find several
approximating polynomials p1(x), p2(x), …, pn(x)
and then choose the one that suits our needs.
p1 (x ) = a0 + a1 (x − x0 )
p2 (x ) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
p3 (x ) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
+ a3 (x − x0 )(x − x1 )(x − x2 )
"
pn (x ) = a0 + a1 (x − x0 ) + ! + an (x − x0 )(x − x1 )!(x − xn −1 )
= pn −1 + an (x − x0 )(x − x1 )!(x − xn −1 )
How do we find ak?
• p1(x) = a0 + a1(x - x0)
f ( x1 ) − f ( x0 )
a0 = f ( x0 ) and a1 =
x1 − x0
f [ x0 ] f [x , x ]
1 0
Solution:
p3(x) = -3+3(x-1)+6(x-1)(x-2)+(x-1)(x-2)(x-3)
Interpolation
Legend:
– piecewise linear function
– quadratic interpolating polynomial
– 6th-order Lagrange polynomial
SPLINE INTERPOLATION
The natural cubic spline function satisfies the
following:
Ø s”(x1) = s”(xn) = 0.
Spline Interpolation
Construction
Introduce variables Mi = s”(xi), i = 1, 2, …, n.
For any two points:
s"( x ) =
( x j − x ) M j−1 + ( x − x j−1 ) M j
x j − x j−1
x j−1 ≤ x ≤ x j
s ( x) =
( x j − x ) M j−1 + ( x − x j−1 ) M j
+
( x j − x ) y j−1 + ( x − x j−1 ) y j
6 ( x j − x j−1 ) x j − x j−1
1
− ( x j − x j−1 )"#( x j − x ) M j−1 + ( x − x j−1 ) M j $%
6
Spline Interpolation
Construction
Ensuring the continuity of s’(x), lead to the
following system of linear equations
x j − x j−1 x j+1 − x j−1 x j+1 − x j
M j−1 + Mj + M j+1
6 3 6
y j+1 − y j y j − y j−1
= − , j = 2, 3,…, n −1
x j+1 − x j x j − x j−1
• Error ei
(xi, axi+b)
ei = (axi + b ) − yi
• Sum square of errors x
N N
2
E = ∑ ei2 = ∑ [(axi + b ) − yi ]
i =1 i =1
Rewriting, N
∑ (ax
i =1
i + b − yi ) = 0
N
∑ (ax )
2
i + bxi − xi yi = 0
i =1
Least Squares Line
The final form of the least squares equation
becomes
N N
a ∑ xi + bN = ∑ yi
i =1 i =1
N N N
2
a ∑ xi + b∑ xi = ∑ xi yi
i =1 i =1 i =1
(B B)x = B f
T T
distance 2 4 7 11 17
force 2 3.5 4.5 8 9.5
Find the least squares line for the data points
given.
Solution 1
Compute the following quantities
y = 0.514706 x + 1.279412
$ ' * c * * *
+ .
$# ∑ i ∑ i * ∑ yi *
2
x x N '& + .
Coefficients will be solved and r2 evaluated
similarly.
Example
Find the least squares parabola for the four
points (-3, 3), (0, 1), (2,1), and (4, 3).
Solution:
Data Fit to Nonlinear functions
There are two methods to obtain a nonlinear
function that best fits the given data points:
1. Data Linearization
for the five data points (0, 1.5), (1, 2.5), (2,
3.5), (3,5.0), and (4, 7.5).
Solution
• Applying the transformation to the original
points, we obtain
i =1 i =1