Professional Documents
Culture Documents
CA2123 Lecture 9 11
CA2123 Lecture 9 11
CA2123 Lecture 9 11
Engineering Methods
Dr XQ He
Dept. Architecture & Civil Engineering
City University of Hong Kong
Tel: 3442 4760 Fax: 2788 7612
E-mail: bcxqhe@cityu.edu.hk
1
Topics in the Next 3 Weeks
2
References
3
Introduction
4
Introduction
1.Why need curve fitting?
a set of discrete 7
(mm)
5
how to estimate the 4
values at points 3
1
test points, e.g. δ = ? 0
when P = 4 KN. 0 2 4 6
P (KN)
8 10 12 14 16
(1) interpolation
Curve Fitting
(2) regression. 9
Introduction
The choice of methods depends on error in data
Interpolation
120
100
interpolation
Precise data 80
Temperature (deg F)
60
20
0
0 1 2 3 4 5
Time (s)
Regression
9
8
regression
7
0
0 2 4 6 8 10 12 14 16
x
10
Least-Squares Regression
11
Least-Squares Regression
1. Linear model
Straight line is the simplest model characterizing
trend without passing through particular points.
Mathematical representation for the straight line:
y a0 a1 x
How to determine the constants a0 and a1?
How to measure goodness of fit of the line to the data?
ei =
predicted
13
Least-Squares Regression
i 1 2 3 4 5 6 7 8
An example:
x 1.00 2.20 5.30 6.10 7.30 9.90 11.50 14.10
y 2.10 2.94 4.00 3.80 6.11 5.82 5.67 8.02
9
8
: data point
7
6
5
y
4
3 Regression model:
y = a0 + a1 x
2
1
0
0 2 4 6 8 10 12 14 16 14
x
Least-Squares Regression
Residual at each point ei
9
8
: data point
y8
7
y5
e7
6 e6
e5
5 y6 y7
y
e4
4
y2 y3
y4 ei: Residual
3
2
y1 Regression model:
1 y = a0 + a1 x
0
0 2 4 6 8 10 12 14 16
x 15
Least-Squares Regression
Criterion for a ‘best’ fit:
The ‘best’ fit is the one that minimizes the sum of squared
residuals at all data points, i.e.
ei = yi a0 a1 xi
n n
min S r = min e = min yi a0 a1 xi
2 2
i
i=1 i=1
n
(Consider: why do not use S r = y
i=1
i a0 a1 xi ?)
16
Least-Squares Regression
The above criterion requires that coefficients a0 and a1 must
satisfy the following conditions:
S r S r
0; 0 least-squares rule
a0 a1
Since
S r n 2 S r n 2
=
i 0 1 i
y a a x yi a0 a1 xi
a0 a0 i=1 =
a1 a1 i=1
n
yi a0 a1 xi 2
n
yi a0 a1 xi
2
i=1 a0
i=1 a1
n
2 yi a0 a1 xi
n
2 yi a0 a1 xi xi
i=1 i=1
17
Least-Squares Regression
We have
S r n
a 2 ( yi a0 ai xi ) 0
0 i 1
S r 2 [( y a a x ) x ] 0
n
i 0 i i i
a1 i 1
y x x x y
i
2
i i i i
n n a0 i=1 i=1 i=1 i=1
na0 xi a1 yi n
n
2
i=1 i=1 n x xi
2
i
i=1 i=1
n n 2 n n n n
xi a0 xi a1 xi yi n xi yi xi yi
i=1 i=1 i=1
a1 i=1 i=1 i=1
2
n
n
n x xi
2
i
i=1 i=1
i 1 2 3 4 5 6 7 8
x 1.00 2.20 5.30 6.10 7.30 9.90 11.50 14.10
Solution:
Linear model: y a0 a1 x
8 8
x
i 1
i 57.40, x
i 1
2
i 553.50
8 8
y
i 1
i 38.46, x y
i 1
i i 333.456
20
Least-Squares Regression
n n n n n n n
y x x x y
i
2
i i i i n xi yi xi yi
a0 i=1 i=1 i=1 i=1
2
, a1 i=1 i=1 i=1
2
n
n n
n
n x xi
2
i n x xi
2
i
i=1 i=1 i=1 i=1
(38.46)(553.5) (57.4)(333.456)
a0 1.8948
8(553.5) 57.4
2
8(333.456) (57.4)(38.46)
a1 0.4060
8(553.5) 57.4
2
y = 1.8946 + 0.4060 x
21
Least-Squares Regression
Plot the results:
9
8
: data point
7
6
5
y
4
3 y = 1.8946 + 0.4060x
1
0
0 2 4 6 8 10 12 14 16
x
22
Least-Squares Regression
2. Polynomial regression
Quadratic y a0 a1 x a2 x 2
Cubic y a0 a1 x a2 x 2 a3 x 3
General y a0 a1 x a2 x 2 a3 x 3 am x m
23
Least-Squares Regression
S r n n
2
n
0 na0 (i xi )a1 ( xi )a 2 yi
a0 1 i 1 i 1
S r n n
2
n
3
n
0 ( xi )a0 ( xi )a1 ( xi )a2 ( xi yi )
a1 i 1 i 1 i 1 i 1
S r n 2 n
3
n
4
n
2
0 ( x i ) a 0 ( x i ) a 1 ( x i ) a 2 ( x i yi )
a 2 i 1 i 1 i 1 i 1
24
Least-Squares Regression
The equations can be written in a matrix form as
n n
n
n x i x2
i i y
n i=1 i=1
a0 ni=1
x
n n
3
i i i
x 2
x i 1 a x y
i
a2 i=n 1
i=1 i=1 i=1
n n n
xi2 x2 y
i=1
i
x
i=1
3
i=1
xi
4
i=1
i i
y = 2.47857+2.35929x+1.86071x2
26
Least-Squares Regression
The results are shown in the figure below, together with the
linear model for comparison.
Clearly, the quadratic model is more accurate for this example.
80
: data point
: quadratic model
60 : linear model
y
40
20
0
0 2 4 6
x 27
Least-Squares Regression
Now we turn our attention to polynomial models of mth-order
Residual:
ei = yi (a0 a1 xi a2 xi2 a3 xi3 am xim )
y
n n
Sr =
i =1
e i2 =
i =1
i (a 0 a1 xi a 2 xi2 a 3 xi3 m 2
a m xi )
n n n
n
n x i x 2
i m
ix i y
n i=1
n
i=1
n
i=1
n a 0 n
i=1
x xim 1 a xi y i
x x
2 3
i i i
1 i=1
n
i=1 i=1 i=1 i=1
a2 n
n n n
xi2 i
x 3
i
x 4
xi xi y i
m2 2
symmetric matrix! 29
Least-Squares Regression
It is obvious that the linear, quadratic and cubic models are
special cases in this equation.
x 0 1.0 1.5 2.3 2.5 4.0 5.1 6.0 6.5 7.0 8.1 9.0
y 0.2 0.8 2.5 2.5 3.5 4.3 3.0 5.0 3.5 2.4 1.3 2.0
x 9.3 11.0 11.3 12.1 13.1 14.0 15.5 16.0 17.5 17.8 19.0 20.0
y -0.3 -1.3 -3.0 -4.0 -4.9 -4.0 -5.2 -3.0 -3.5 -1.6 -1.4 -0.1
30
Least-Squares Regression
Solution:
2
f(x)
-2
-4
-6 31
0 5 10 15 20 25
x
Least-Squares Regression
It is evident from the figure that both linear and quadratic
models are not suitable in this case. Try a cubic model.
y a0 a1 x a2 x 2 a3 x 3
x
i=1
4
i 752835.2, x
i=1
5
i 12780147.7, x
i=1
6
i 223518116.8
24 24 24 24
y
i=1
i 1.30, x
i=1
i yi 316.9, x
i=1
2
i yi 6037.2, x
i=1
3
y 9943.36
i i
2
f(x)
-2
-4
-6 34
0 5 10 15 20 25
x
Least-Squares Regression
Comparison of results with different model:
6
2
y
-2 : data point
: 3rd-order
: 5th-order
-4 : 9th-order
-6
0 5 10 15 20
x 35
Least-Squares Regression
Comparison of results in Example 3 but with less data points:
6
: data point
4
: 3rd-order
: 9th-order
2
y
-2
-4
-6
0 5 10 15 20
x 36
Least-Squares Regression
n
Standard deviation St ( yi y ) 2
St S r
Coefficient of determination: r 2
St
y
y i
4.8075 St ( yi y ) 2 26.2710
n
S r ei2 2.91 St S r
r2 0.8892
St 38
Least-Squares Regression
Compare two models
39
Least-Squares Regression
3. Summary of solution process:
40
Least-Squares Regression
4. Discussion:
42
Assignment 9
Interpolation: Polynomials
44
Interpolation: polynomials
What is interpolation?
interpolation f(x)
Evaluate
Differentiate
Integrate.
47
Interpolation: polynomials
1. Undetermined coefficient method
It needs to satisfy
48
Interpolation: polynomials
rewrite these two equations in matrix form
1 x1 a 0 y1
1 x a y
2 1 2
y( x) a0 a1 x 0.3583519( x 1)
50
Interpolation: polynomials
Solution 2:
x1 1, y1 0, x2 4, y2 1.386294,
x2 y1 x1 y2 4(0) 1(1.386294)
a0 0.4620981
x2 x1 4 1
y2 y1 1.386294 0
a1 0.4620981
x2 x1 4 1
y( x) a0 a1 x 0.4320981( x 1)
solution 1
2 solution 2 y =ln(x)
1.5
y
true value
0.5
0
1 2 3 4 5 6 7 8
x
52
Interpolation: polynomials
What if we have more than two data points?
1.2 Polynomial interpolation of nth-order: A general case
We may fit a polynomial of order one less than the number of
data points, i.e., four points give a 3rd-order polynomial.
The 3rd-order polynomial is
y a 0 a1 x a 2 x 2 a3 x 3
For the four points, we have
53
Interpolation: polynomials
or in matrix form
1 x1 x12 x13 a 0 y1
1 x2 x 22 x 23 a1 y 2
1 3
x3 x32 x 3 a 2 y 3
3
1 x4 x 42 x 4 a3 y 4
Solution:
3rd-order polynomial: y a 0 a1 x a 2 x 2 a3 x 3
Therefore, 15
: data point
: 3rd-order interpolation
y 2 x x2 x3 y
12
0
-1.0 -0.5 0.0 0.5 1.0 1.5 2.0 56
x
Interpolation: polynomials
Then,
57
Interpolation: polynomials
The function is obtained as
y y1
y y1 2 ( x x1 )
x 2 x1
2.2 (n-1)th-order interpolation polynomial
When there are three data points, a 2nd-order interpolation
is needed and the function is expressed in the form of
y b0 b1 ( x x1 ) b2 ( x x1 )( x x2 )
where
58
Interpolation: polynomials
y( x1 ) y1 , b0 y1
y y
y ( x2 ) y 2 , b1 2 1
x2 x1
y 3 y 2 y 2 y1
x x 2 x 2 x1
y ( x3 ) y 3 , b2 3
x3 x1
59
Interpolation: polynomials
Introduce following notations:
yi y j
f [ xi , x j ]
xi x j
yi y j y j yk divided
difference
xi x j x j xk f [ xi , x j ] f [ x j , xk ]
f [ xi , x j , xk ]
xi xk xi xk
f [ xn , xn 1 , , x2 ] f [ xn 1 , xn 2 , , x1 ]
f [ xn , xn 1 , , x1 ]
xn x1
Coefficients can thus be computed in terms of divided
differences as
b0 y1
60
Interpolation: polynomials
y2 y1
b1 f [ x2 , x1 ]
x2 x1
y3 y2 y2 y1
x x x2 x1 f [ x3 , x2 ] f [ x2 , x1 ]
b2 3 2 f [ x3 , x2 , x1 ]
x3 x1 x3 x1
f [ x4 , x3 , x2 ] f [ x3 , x2 , x1 ]
b3 f [ x4 , x3 , x2 , x1 ]
x4 x1
……
f [ xn ,..., x2 ] f [ xn 1 ,..., x1 ]
bn 1 f [ xn ,..., x2 , x1 ]
xn x1
61
Interpolation: polynomials
Substituting these expressions into the interpolation
polynomial of order n-1 yields
y ( x) y1 ( x x1 ) f [ x2 , x1 ] ( x x1 )( x x2 ) f [ x3 , x2 , x1 ]
( x x1 )( x x2 )( x x3 ) f [ x4 , x3 , x2 , x1 ]
( x x1 )( x x2 ) ( x xn 1 ) f [ xn , xn 1 ,, x1 ]
Newton divided difference formula
Comparing with the undetermined coefficient method, Newton
divided difference method offers two advantages:
(a) computation of a Vandermonde matrix equation is avoided.
(b) inverse of matrix is not needed.
62
Interpolation: polynomials
Example 3: Redo Example 2 but this time, by using Newton
divided difference method.
xi -1 0 1 2
yi 1 2 5 16
Solution:
Since there are 4 data points we need to find a 3rd-order
interpolation polynomial whose coefficients are
b0 y1 : b0 1
63
Interpolation: polynomials
y y 2 1 xi -1 0 1 2
f [ x2 , x1 ] 2 1 1,
x2 x1 0 1 yi 1 2 5 16
y3 y 2 5 2 y ( x) y1 ( x x1 ) f [ x2 , x1 ]
f [ x3 , x2 ] 3,
x3 x2 1 0 ( x x1 )( x x2 ) f [ x3 , x2 , x1 ]
y4 y3 16 5
f [ x4 , x3 ] 11, ( x x1 )( x x2 )( x x3 ) f [ x4 , x3 , x2 , x1 ]
x4 x3 2 1
f [ x3 , x2 ] f [ x2 , x1 ] 3 1
f [ x3 , x2 , x1 ] 1,
x3 x1 1 (1)
f [ x4 , x3 ] f [ x3 , x2 ] 11 3
f [ x4 , x3 , x2 ] 4,
x4 x2 20
f [ x4 , x3 , x2 ] f [ x3 , x2 , x1 ] 4 1
f [ x4 , x3 , x2 , x1 ] 1,
x4 x1 2 (1)
b1 f [ x2 , x1 ] 1, b2 f [ x3 , x2 , x1 ] 1, b3 f [ x4 , x3 , x2 , x1 ] 1.
64
Interpolation: polynomials
The interpolation polynomial we’re looking for is
y( x) 1 ( x x1 ) ( x x1 )( x x2 ) ( x x1 )( x x2 )( x x3 )
Conclusion:
There is one unique polynomial of degree n-1 that passes
through n points.
65
Interpolation: polynomials
In addition, the computation of coefficients can also be done
by using a working table. For a 2rd-order problem, the table
works as follows
b0 b1 b2
66
Interpolation: polynomials
Example 4: Employ Newton divided difference method to
solve Example 2 and use a working table to calculate b0, b1,
b2, and b3.
Solution:
b0 b1 b2 b3
67
Interpolation: polynomials
b0 = b1 = b2 = b3 = 1, so
y( x) 1 ( x x1 ) ( x x1 )( x x2 ) ( x x1 )( x x2 )( x x3 )
b0 b1 b2 b3 b4
x y
-1.0 -2.1 8 -6.5 2.83 -0.78
-0.7 0.3 2.8 -1.96 1.27
-0.2 1.7 0.25 0.208
0.6 1.9 0.5
1.0 2.1
70
Interpolation: polynomials
Thus,
b0 y1 2.1,
b1 f [ x2 , x1 ] 8,
b2 f [ x3 , x2 , x1 ] 6.5,
b3 f [ x4 , x3 , x2 , x1 ] 2.8359,
b4 f [ x5 , x4 , x3 , x2 , x1 ] 0.7795.
2.5
1.5
0.5
0 data point
-0.5
4th-order poly.
-1
-1.5
-2
-2.5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
72
Interpolation: polynomials
where the given points are (x1, y1), ….. , (xn, yn), and
n
x xj
Li ( x )
j 1 xi xj
j i
73
Interpolation: polynomials
no (x-xi)
or in expansion as no (xi-xi)
( x x1 )...( x xi 1 )( x xi 1 )...( x xn )
Li ( x)
( xi x1 )...( xi xi 1 )( xi xi 1 )...( xi xn )
As a simple case, the polynomial passing through two points
(x1, y1) and (x2, y2) is
( x x2 ) ( x x1 )
y ( x) y1 y2
( x1 x2 ) ( x2 x1 )
The polynomial passing through three points (x1, y1), (x2, y2),
and (x3, y3) is
( x x2 )( x x3 ) ( x x1 )( x x3 ) ( x x1 )( x x2 )
y ( x) y1 y2 y3
( x1 x2 )( x1 x3 ) ( x2 x1 )( x2 x3 ) ( x3 x1 )( x3 x2 )
74
Interpolation: polynomials
Tip to construct Li(x):
75
Interpolation: polynomials
Example 6. Given points (x1, y1) = (-2,4), (x2, y2) = (0,2), and
(x3, y3) = (2, 8), find the Lagrange interpolating polynomial.
Solution:
( x x2 )( x x3 ) ( x x1 )( x x3 ) ( x x1 )( x x2 )
y ( x) y1 y2 y3
( x1 x2 )( x1 x3 ) ( x2 x1 )( x2 x3 ) ( x3 x1 )( x3 x2 )
76
Interpolation: polynomials
y
12
10
2
x
-2 -1 0 1 2
77
Interpolation: polynomials
Example 7. A problem with higher order interpolation
polynomials
x = [ -2, -1, 0, 1, 2, 3, 4],
y = [ -15, 0, 3, 0, -3, 0, 15].
Solution:
For this 7-point problem, a 6th-order LP is needed.
( x x2 )( x x3 )( x x4 )( x x5 )( x x6 )( x x7 )
L1 ( x) y1 y1
( x1 x2 )( x1 x3 )( x1 x4 )( x1 x5 )( x1 x6 )( x1 x7 )
15( x 1) x( x 1)( x 2)( x 3)( x 4)
(2 1)(2 0)(2 1)(2 2)(2 3)(2 4)
0.02083( x 1) x( x 1)( x 2)( x 3)( x 4)
78
Interpolation: polynomials
( x x1 )( x x3 )( x x4 )( x x5 )( x x6 )( x x7 )
L2 ( x) y2 y2
( x2 x1 )( x2 x3 )( x2 x4 )( x2 x5 )( x2 x6 )( x2 x7 )
0
( x x1 )( x x2 )( x x4 )( x x5 )( x x6 )( x x7 )
L3 ( x) y3 y3
( x3 x1 )( x3 x2 )( x3 x4 )( x3 x5 )( x3 x6 )( x3 x7 )
3( x 2)( x 1)( x 1)( x 2)( x 3)( x 4)
(0 2)(0 1)(0 1)(0 2)(0 3)(0 4)
0.0625( x 2)( x 1)( x 1)( x 2)( x 3)( x 4)
( x x1 )( x x2 )( x x3 )( x x5 )( x x6 )( x x7 )
L4 ( x) y4 y4
( x4 x1 )( x4 x2 )( x4 x3 )( x4 x5 )( x4 x6 )( x4 x7 )
0
79
Interpolation: polynomials
( x x1 )( x x2 )( x x3 )( x x4 )( x x6 )( x x7 )
L5 ( x) y5 y5
( x5 x1 )( x5 x2 )( x5 x3 )( x5 x4 )( x5 x6 )( x5 x7 )
3( x 2)( x 1)( x 0)( x 1)( x 3)( x 4)
(2 2)(2 1)(2 0)(2 1)(2 3)(2 4)
0.0625( x 2)( x 1) x( x 1)( x 3)( x 4)
( x x1 )( x x2 )( x x3 )( x x4 )( x x5 )( x x7 )
L6 ( x) y6 y6
( x6 x1 )( x6 x2 )( x6 x3 )( x6 x4 )( x6 x5 )( x6 x7 )
0
( x x1 )( x x2 )( x x3 )( x x4 )( x x5 )( x x6 )
L7 ( x) y7 y7
( x7 x1 )( x7 x2 )( x7 x3 )( x7 x4 )( x7 x5 )( x7 x6 )
15( x 2)( x 1)( x 0)( x 1)( x 2)( x 3)
(4 2)(4 1)(4 0)(4 1)(4 2)(4 3)
0.02083( x 2)( x 1) x( x 1)( x 2)( x 3) 80
Interpolation: polynomials
The Lagrange polynomial is:
81
Interpolation: polynomials
Important!
(a) Moving from the 1st-order to up to 5th-order improves
the interpolation accuracy.
(b) However, the 7th-order interpolation instead produces
wild oscillations. This situation is not uncommon for
high-order polynomial interpolation.
(c) Rule of thumb: do not use interpolation of order higher
than 5.
(d) If you believe that the accuracy of the 5th-order
interpolation is not sufficient, consider other methods of
interpolation.
82
Look at an example of 8 data points below and note the 7th-
order results which is oscillatory.
CISE301_Topic5 84
Summary
85
Summary
Regression models estimate f(x) and may be
used for forecasting future and past values.
Interpolation models may be suitable when
measurements are believed to be exact.
Interpolation models estimate values
between known data points.
NOT for forecasting
86
Interpolation: Splines
Why splines?
Questions to be answered in the last section:
For problems with many data points or local abrupt changes,
high order polynomial interpolation is a bad idea. Then what
methods should we use?
Solution: Break the whole interval defined by n data points
(x1, ……, xn) into n -1 subintervals and over each subinterval,
use low order piecewise polynomials ─ splines.
Take a set of 4 data points as an example. Instead of seeking
for a 3th-order interpolating polynomial over interval [x1, x4] as
has been done in the last section, we divide the interval into
87
Interpolation: Splines
three subintervals I1 [ x1 , x2 ], I 2 [ x2 , x3 ] and I 3 [ x3 , x4 ] as shown
in the figure
y ( x3 , y3 )
( x2 , y 2 )
( x4 , y 4 )
x
( x1 , y1 )
3rd-order 5th-order
real solution
spline
7th-order
89
Interpolation: Splines
1. Piecewise linear interpolation
Set of data points : ( x1 , y1 ), ( x2 , y2 ), ( x3 , y3 ), ( x4 , y4 ) with x1 x2 x3 x4
Solution:
x : I1 [0, 1], I 2 [1, 2] , I 3 [2, 3]
The three subintervals are
y : I1 [0, 1], I 2 [1, 4] , I 3 [4, 3]
x x2 x x1 x 1 x0
y1 y 2 0 1 x
x1 x2 x2 x1 0 1 1 0
x x3 x x2 x2 x 1
y ( x) y2 y3 1 4 3x 2
x2 x3 x3 x2 1 2 2 1
x x4 x x3 x 3 x2
y3 y4 4 3 x 6
x3 x4 x4 x3 23 3 2
91
Interpolation: Splines
y
4
x, 0 x 1 3
y ( x) 3 x 2, 1 x 2 2
x 6, 2 x 3
1
0 x
0 1 2 3
Piecewise linear interpolation
Given n-1 subintervals [x1, x2], ……, [xn-1, xn], the quadratic
splines in each subinterval are given by
a1 x 2 b1 x c1 , x1 x x2
a2 x b2 x c2 , x2 x x3
2
y ( x)
:
an 1 x 2 bn 1 x cn 1 , xn 1 x xn
93
Interpolation: Splines
An example with 3 subintervals:
94
Interpolation: Splines
How to determine the coefficients ai, bi, ci (1≤i ≤ n-1)?
There are 3(n-1) unknown coefficients in the n -1 quadratic
splines, which need to be determined from the following
conditions:
(a) The values of adjacent splines must be equal to the function
values at the interior knots (2*(n-2)).
(b) The first and last splines must go through the end points (2)
(c) The first derivatives at the interior knots must be equal (n-2).
(d) Assume that the second derivate is zero at the first point (1).
*The bracketed number marked in red is the number of
equations which will be used to determine the coefficients.
95
Interpolation: Splines
(a) The values of adjacent splines must be equal to the function
values at the interior knots, i.e.
ai 1 xi2 bi 1 xi ci 1 yi , i 2, ... ..., n 1
(b) The first and last splines must go through the end points, i.e.
a1 x12 b1 x1 c1 y1
an 1 xn2 bn 1 xn cn 1 yn
96
Interpolation: Splines
(c) The first derivatives at the interior knots must be equal, i.e.
yi' 1 ( xi ) 2ai 1 xi bi 1 , i 2, ... ..., n 1
(d) Assume that the second derivate is zero at the first point .
a1 0
97
Interpolation: Splines
Example 2: Fit the following data with quadratic splines and
estimate the value of y(5).
Solution:
We need 3 subintervals for 4 data points and the quadratic
splines in each subinterval are
a1 x 2 b1 x c1 , 3 x 4.5
y ( x) a2 x 2 b2 x c2 , 4.5 x 7
a x2 b x c , 7 x9
3 3 3
98
Interpolation: Splines
(a) Equal values at interior knots
For first interior knot: x2 4.5
100
Interpolation: Splines
(c) Equal first derivatives at the interior knots.
4 .5 1 0 0 0 0 0 0 b1 1
0 0
20.25 4.5 1 0 0 0 c1 1
0 0 49 7 1 0 0 0 a 2 2.5
0 0 0 0 0 49 7 1 b2 2.5
3 1 0 0 0 0 0
0 c2 2.5
0 0 0 0 0 81 9 1 a3 0.5
1 0 9 1 0 0 0 0 b3 0
0 0 14 1 0 14 1 0 c3 0
102
Interpolation: Splines
Solving these 8 equations with 8 unknowns, we can find that:
a1 0, b1 1, c1 5.5
a2 0.64, b2 6.76, c2 18.46
a3 1.6, b3 24.6, c3 91.3
Hence,
y( x) x 5.5, 3.0 x 4.5
103
Interpolation: Splines
3.5
3.0
2.5
2.0
y
1.5
1.0
0.5
0.0
3 4 5 6 7 8 9
x
Results of Example 2
104
Interpolation: Splines
Example 3. The upward
velocity of a rocket is
given as a function of time
in table below. Find the
velocity and acceleration
at t =16 seconds using
quadratic splines.
t (sec) 0 10 15 20 22.5 30
105
Interpolation: Splines
Solution:
v(t) a 2 t 2 b2 t c 2 , 10 t 15
v(t) a 4 t b4 t c 4 , 20 t 22.5
2
v(t) a5 t b5 t c5 , 22.5 t 30
2
106
Interpolation: Splines
Setting up equations to determine coefficients
(a) Equal values at interior knots
t22 a1 t2b1 c1 v2 , (10) 2 a1 10b1 c1 227.04
t 22 a2 t 2b2 c2 v2 , (10) 2 a2 10b2 c2 227.04
(b) First and last splines pass through the end points
t12 a1 t1b1 c1 v1 , c1 0
t62 a5 t6b5 c5 v6 , (30) 2 a5 30b5 c5 901.67
109
Interpolation: Splines
The matrix equation is
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a1 0
100 10 1 0 0 0 0 0 0 0 0 0 0 0 0 b1 227 .04
0 0 0 100 10 1 0 0 0 0 0 0 0 0
0 c1
227 .04
0 0 0 225 15 1 0 0 0 0 0 0 0 0 0 a2 362 .78
0 0 0 0 0 0 225 15 1 0 0 0 0 0 0 b2 362 .78
0 0 0 0 0 0 400 20 1 0 0 0 0 0 0 c2 517 .35
0 0 0 0 0 0 0 0 0 400 20 1 0 0 0 a3 517 .35
0 0 0 0 0 0 0 0 0 506 .25 22.5 1 0 0 0 b3 602 .97
0 0 0 0 0 0 0 0 0 0 0 0 506 .25 22.5 1 c3 602 .97
0 0 0 0 0 0 0 0 0 0 0 0 900
901 .67
30 1 a4
20 1 0 20 1 0 0 0 0 0 0 0 0 0 0 b4 0
0 0 0 30 1 0 30 1 0 0 0 0 0 0 0 c4 0
0 0 0 0 0 0 40 1 0 40 1 0 0 0 0 a5 0
0 0 0 0 0 0 0 0 0 45 1 0 45 1 0 b5 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 c5 0
110
Interpolation: Splines
i ai bi ci
1 0 22.704 0
111
Interpolation: Splines
Therefore, the piecewise quadratic splines are given by
v(t ) 22.704t , 0 t 10
x -1 1 0 -2 2 3
y 1 0 3 -4 2 5
115
Assignment 10
Q. 3. The upward velocity of a rocket
is given as a function of time in table
below. Find the velocity and
acceleration at t =16 seconds using
the Newton divided difference
method.
t (sec) 10 15 20 22.5 30
v (m/sec) 227.04 362.78 517.35 602.97 901.67
0.1x 2 , 0 x 1
(a ) y ( x )
9.3 x 2
18.4 x 9.2, 1 x 1.3
x2 , 1 x 2
( b) y ( x )
4, 2 x 13
117
Assignment 10
Q. 6. Find the linear splines for the data given below.
x -2 -1 0 1 2 3 4
y -1 0 1.5 0 1 2.5 3