CA2123 Lecture 9 11

You might also like

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

CA2123

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

Lecture 9-11. Curve Fitting Techniques

Lecture 9 Least-Squares Regression

Lecture 10 Interpolation: Polynomials

Lecture 11 Interpolation: Splines

2
References

1. “Numerical Analysis” by Vithala A. Patel, 1994.

2. “Numerical Mathematics and Computing” by Ward


Cheney & David Kincaid, 1994.

3. “Calculus” by Stanley I. Grossman, 1988.

4. “Calculus” by C. Henry Edwards & David E. Penney, 1998.

5. “Technical Calculus” by Dale Ewen et al. 1998.

3
Introduction

1. Why need curve fitting?

2. What is curve fitting?

3. Methods of curve fitting

4
Introduction
1.Why need curve fitting?

In many applications, the results of an experiment is a


table of data, not a function .
Quite often, we want to represent these data by using a
mathematical model with which we can determine
important characteristics of the data, such as the rate of
change anywhere on the curve, the local minimum and
maximum points, etc. For this purpose, we must try to
find a function which, in some senses, “best fit” the
experimental data.
5
Introduction
Example: the test of a RC column under compression.

Test setup Compression test


6
Introduction
9
Data is obtained for 8
: test data point

a set of discrete 7

points in the test, but 6

 (mm)
5
how to estimate the 4

values at points 3

between the discrete 2

1
test points, e.g. δ = ? 0
when P = 4 KN. 0 2 4 6
P (KN)
8 10 12 14 16

No exact answer, but a good


guess is possible ─ P: axial compressive load
approximation is needed! δ: the displacement
7
Introduction
2. What is curve fitting?
Constructing functions whose graphs are curves that "best”
approximates a given collection of points ─ curve fitting.

We can make approximations y = y (x) by using


(1) linear functions; y  a0  a1 x
(2) polynomials; y  a0   am x m
m 1
(3) exponential functions; y  ae bx

(4) power functions; y  ax b


(5) logarithmic functions; and y  a ln x  b
(6) some others.
where constants are to be determined. 8
Introduction
With the approximated function, you can
(1) illustrate the data trend;

(2) estimate the function value at any point; and


(3) obtain important parameters, such as slope, gradient,
minimum and maximum, etc. from the data.

3. Methods of curve fitting

(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

 Forced through each data point 40

20

0
0 1 2 3 4 5
Time (s)

 Regression
9

8
regression
7

 Noisy data (contain error) 6

Represent trend of the data


f(x)
 4

 Not forced through all points 2

0
0 2 4 6 8 10 12 14 16
x
10
Least-Squares Regression

In this section, we discuss the least-squares regression technique.


The major questions to be answered include:

(1) What model, i.e., approximate function, is to be used?


(2) How to determine the unknown constants in the model?

(3) How good is the fit?

(4) Solution procedures.

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?

To this end, we need to look at the discrepancy between the


true values and the approximated values.
12
Least-Squares Regression
For each given point (xi, yi), the discrepancy is
ei  yi  a0  a1 xi residual

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

Reorganize the equations in terms of two unknowns: a0 and a1


n n n
i yi   a0   a1 xi  0
1 i 1 i 1
n n n
 y x   a x   a x2  0
i 1 i i i 1 0 i i 1 1 i
18
Least-Squares Regression
Equations: Solution:
n n n n

 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 

Note: The least-squares rule ensures that the approximation


thus determined is the best one within the model chosen.
19
Least-Squares Regression
Example 1. Use a linear model to fit the data in the table below.

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

y 2.10 2.94 4.00 3.80 6.11 5.82 5.67 8.02

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

Use polynomials of 2nd-order or above in the model.

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

Must find values of a0 , a1, a2, … am.

23
Least-Squares Regression

For quadratic model, y  a0  a1 x  a2 x 2


n
min S r   [ yi  (a0  a1 xi  a2 xi2 )]2
i 1

According to least-squares rule, minimize Sr by taking derivatives

 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

Once constants a0 , a1, a2 have been obtained from this


matrix equation, the quadratic model is determined.
How to remember this equation in an easy way?
25
Least-Squares Regression
Example 2. Fit a quadratic model to the data in the table below.
n = 6,
xi yi
x  x  55,  x  255,
4
0 2.1 i  15, 2
i
3
i
 xi  979
1 7.7
 y  152.6,  x y  585.6,
2
2 13.6 i i

i
xi yi  2488 .8
3 27.2
4 40.9 6 15 55  a0  152 .6  a0  2.47857 
5 61.1 15 55 225  a   585 .6     
a 
 1  2 . 35929 
  1   
55 225 979  a2  2488 .8 a  1.86071 
 2  

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 )

• Sum of squared residuals

 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 )

Following a similar least-squares process to minimize Sr,


S r
 0, (i  0,......, m)
ai
28
Least-Squares Regression
a matrix equation can then be derived as

 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 
m2 2

 i=1 i=1 i=1 i=1      i=1 


       a    
n m  m
2m 
n n n n
 xm y 
 x i  i  i   
m 1 m 2
x x x 
 i=1 i=1 i=1 i=1
i
 
 i=1
i i


symmetric matrix! 29
Least-Squares Regression
It is obvious that the linear, quadratic and cubic models are
special cases in this equation.

Example 3. Employ an appropriate regression model to fit the


data in the table.

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:

(1) To choose an appropriate regression model, we need to


first look at the data trend in the figure.
6

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

(2) Determination of constants


 n n n
  n 
 n x x i
2
i  x 3
i    i y
 n i=1
n
i=1
n
i=1
n  a   ni=1 
 x 4  xy 
 x x  
2 3 0
xi  
i i i
  a1  i i

n
i=1 i=1
n
i=1
n
i=1
n    ni=1

5 a 2
 xi2 x x 3
i
4
i  xi    xi y i 
2

 i=1 i=1 i=1 i=1  a3   i=1 


 n 3 n n n
6
 n 
  xi x x   xi y i 
4 5 3
i i x i 
 i=1 i=1 i=1 i=1   i=1 
32
Least-Squares Regression
24 24 24
n  24, x
i=1
i  229.6, x
i=1
2
i  3060.2, x i=1
3
i  46342.8
24 24 24

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

 24 229.6 3060.2 46342.8   a0    1.30 


 229.6 3060.2 46342.8 752835.2   a1    316.9 
     
 3060.2 46342.8 752835.2 12780147 .7  a2    6037 .2 
46342.8 752835.2 12780147 .7 223518116 .8  a   9943.36
  3   
33
Least-Squares Regression
 a0    0.3593
a   2.3051  Regression model
1
     y = - 0.359 + 2.305x - 0.353x2 + 0.012x3
a2   0.3532
a   0.0121  (3) Plot the model and compare with the data
 3  
points in the figure to evaluate the fit.
6

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

How good is the fit?


Simple statistics of the data:
Arithmetic mean y
 y i

n
Standard deviation St   ( yi  y ) 2
St  S r
Coefficient of determination: r 2 
St

Note: Here, r2 is a value between 0 and 1, quantifying goodness


of fit but not the square of anything. A higher value of r2
indicates that the model fits data better. 37
Least-Squares Regression
Take Example 1 as an example to show how to calculate
the statistical quantities.
xi 1.00 2.20 5.30 6.10 7.30 9.90 11.50 14.10
yi 2.10 2.94 4.00 3.80 6.11 5.82 5.67 8.02
y (xi) 2.30 2.79 4.05 4.37 4.86 5.91 6.56 7.62
( yi  y ) 2 7.33 3.49 0.65 1.02 1.70 1.03 0.74 10.32

ei -0.20 0.15 -0.05 -0.57 1.25 -0.09 -0.89 0.40

ei2 0.04 0.02 0.00 0.32 1.56 0.01 0.79 0.16

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

If you do not know which one is more appropriate for


the data, fit both, compare the results and then
(1) reject the one scientifically unreasonable;

(2) reject the one with greater value of Sr.

39
Least-Squares Regression
3. Summary of solution process:

 Given paired data points (xi, yi);


 Produce a scatter plot of the paired data points;
 Choose an suitable regression model;
 Determine the constants in the model;
 Evaluate the fit;
 Analyze the result.

40
Least-Squares Regression
4. Discussion:

 A higher-order model normally leads to a model more


mathematically accurate but not always more
scientifically reasonable;
 To obtain more accurate regression, one needs:
(a) more paired data points, and
(b) more underlying scientific background of the
problem being studied;
 Use of a higher-order model will significantly
increase the computational effort.
41
Assignment 9

Q.1. Based on the experimental results in the following


table, approximate the relationship y = y (x) by using the
least squares regression technique with
(a) a linear model y = a0 + a1 x ;
(b) a quadratic model y = a0 + a1 x + a2 x2; and
(c) calculate r2 and Sr for both models.

x 3.5 4.0 4.8 3.3 2.7 1.5 0.6


y 1.2 1.8 1.0 2.5 2.9 4.5 5.5

42
Assignment 9

Q.2. Hook’s law states that when a force F is applied to a


spring of uniform material, the increase in the length x
of the spring is proportional to the applied force. In
order to determine the spring constant k, an experiment
was performed and data were obtained in the table
below. Use the least squares regression technique to
determine k.

x 0.15 0.25 0.42 0.60 0.73 0.9


F 1.5 2.8 3.9 4.8 6.2 7.1

Due Date: 20 Nov 2017


43
Topic in this class

Curve Fitting Techniques:

Interpolation: Polynomials

44
Interpolation: polynomials
What is interpolation?

interpolation f(x)

Interpolation is a process of finding a function whose graph will pass


through a given set of points (x,y). Mathematically, interpolation can
be stated as follows: Given a set of data of the form (xi, yi), i = 1, . . ., n
where the xi are distinct, find a function f (x) such that f (xi) = yi, i = 1, .
. ., n.
45
Interpolation: polynomials
Ways to interpolate:

There are many interpolation methods, which include:


√(1) Undetermined coefficient method,
√(2) Newton divided difference method,
√(3) Polynomial interpolation,
√(4) Spline interpolation, and
(5) Some others, e.g., Hermite interpolation, rational-
function interpolation, etc.
46
Interpolation: polynomials

Polynomials are the most common choice of interpolants


because they are easy to:

Evaluate
Differentiate
Integrate.

47
Interpolation: polynomials
1. Undetermined coefficient method

1.1 Linear interpolation: a simplest case y


(x2, y2)
For a problem with only two data points,
the function is a straight line which (x1, y1)
can be expressed as
y  a0  a1 x x

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

Coefficients a0 and a1 can be obtained as


x 2 y1  x1 y 2 y 2  y1
a0  , a1 
x 2  x1 x 2  x1

Example 1: Find the value of ln2 using linear interpolation


with ln1 = 0 and ln6 = 1.791759. Find ln2 again with ln1=0
and ln4 = 1.386294. Compare the results with the true value
of ln2 = 0.69314. 49
Interpolation: polynomials
Solution 1:
x1  1, y1  0, x2  6, y2  1.791759,
x2 y1  x1 y2 6(0)  1(1.791759)
a0    0.3583519
x2  x1 6 1
y2  y1 1.791759  0
a1    0.3583519
x2  x1 6 1

y( x)  a0  a1 x  0.3583519( x  1)

y(2)  0.3583519(2  1)  0.3583519


error :   (0.69314  0.3583519) / 0.69314  48.3%

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)

y(2)  0.4620981(2  1)  0.4620981


error :   (0.69314  0.4620981) / 0.69314  33.3%

Thus, using a shorter interval reduces the relative error. 51


Interpolation: polynomials
2.5

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 

Similarly, for the problem with n data points, one obtains


the following equation system
1 x1 ... x1n 1   a0   y1 
 n 1    y 
 1 x ... x 2   a1   2
2
 
  
: : : :  :   : 
 n 1  
1 xn ... xn  an 1   yn  54
Interpolation: polynomials
Hence, the undetermined coefficient method is not suitable for
problems with a large number of data points.
Example 2: Find the 3rd-order polynomial to interpolate the
function with the following data:
xi -1 0 1 2
yi 1 2 5 16

Solution:

3rd-order polynomial: y  a 0  a1 x  a 2 x 2  a3 x 3

Calculate coefficients from equation


55
Interpolation: polynomials
1  1 1  1 a0   1   a 0  2 
 a  1 
1 0
 0 0   a1   2   1  
     
1 1 
1 1 a 2   5  a 2  1 
  a 3  1 
1 2 4 8  a3  16
18

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

2. Newton divided difference method


2.1 Linear interpolation

When there are only two data points, the function


y  a0  a1 x
can be rewritten as
y  b0  b1 ( x  x1 )

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

In the same way, the general form of an interpolation polynomial


of order n-1 is written as
y ( x)  b0  b1 ( x  x1 )  b2 ( x  x1 )( x  x2 )  b3 ( x  x1 )( x  x2 )( x  x3 )
   bn 1 ( x  x1 )( x  x2 )  ( x  xn 1 )

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 20
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 )

It can be seen after rearrangement that this solution is exactly


the same as what was obtained in Example 2, that is,
y  2  x  x2  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 )

Example 5: Find the interpolation polynomial for the data


below by using Newton divided difference method,
x = [-1.0, -0.7, -0.2, 0.6, 1.0]
y = [-2.1, 0.3, 1.7, 1.9, 2.1]
and calculate y (0.5).
Solution:
Because there are 5 points, a 4th-order polynomial is to be used.
68
Interpolation: polynomials
y2  y1 0.3  2.1 y3  y 2 1.7  0.3
f [ x2 , x1 ]    8, f [ x3 , x2 ]    2.8,
x2  x1  0.7  1 x3  x2  0.2  0.7
y4  y3 1.9  1.7 y5  y4 2.1  1.9
f [ x4 , x3 ]    0.25, f [ x5 , x4 ]    0.5,
x4  x3 0.6  0.2 x5  x4 1  0.6
f [ x3 , x2 ]  f [ x2 , x1 ] 2.8  8
f [ x3 , x2 , x1 ]    6.5,
x3  x1  0.2  1
f [ x4 , x3 ]  f [ x3 , x2 ] 0.25  2.8
f [ x4 , x3 , x2 ]    1.9625,
x 4  x2 0.6  0.7
f [ x5 , x4 ]  f [ x4 , x3 ] 0.5  0.25
f [ x5 , x4 , x3 ]    0.2083,
x5  x3 1  0.2
f [ x4 , x3 , x2 ]  f [ x3 , x2 , x1 ]  1.9625  6.5
f [ x4 , x3 , x2 , x1 ]    2.8359,
x4  x1 0.6  1
f [ x5 , x4 , x3 ]  f [ x4 , x3 , x2 ] 0.2083  1.9625
f [ x5 , x4 , x3 , x2 ]    1.2769,
x5  x2 1  0.7
f [ x5 , x4 , x3 , x2 ]  f [ x4 , x3 , x2 , x1 ] 1.2769  2.8359
f [ x5 , x4 , x3 , x2 , x1 ]    0.7795 69
x5  x1 11
Interpolation: polynomials

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.

and the interpolation polynomial is


y ( x)  2.1  8( x  1)  6.5( x  1)( x  0.7)  2.8359( x  1)( x  0.7)( x  0.2)
- 0.7795( x  1)( x  0.7)( x  0.2)( x  0.6)
A little algebra gives
y(x) = -0.7795 x4 + 1.8225 x3 -1.0338 x2 + 0.2766 x +1.8125
71
Interpolation: polynomials
The value y (0.5) can be readily obtained from

y(0.5) = -0.7795(0.5)4 + 1.8225(0.5)3 -1.0338 (0.5)2


+ 0.2766(0.5) +1.8125 = 1.8714

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

3. Lagrange interpolating polynomials


The Lagrange interpolating polynomial is the polynomial of
order n-1 that passes through the n points.
The general form of the polynomial is
n
y ( x)   Li ( x) yi  L1( x) y1  L 2( x) y 2  .....  Ln ( x) yn
i 1

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):

Full expansion removal of (x - xi) and (xi - xi).

Note that the important properties


1 x  xi
Li ( x)  
0 otherwise
guarantee that
y ( xi )  yi

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 )

( x  0)( x  2) ( x  (2))( x  2) ( x  (2))( x  0)


 4 2 8
(2  0)(2  2) (0  (2))(0  2) (2  (2))(2  0)
x ( x  2) ( x  2)( x  2) x ( x  2)
 4 2 8
8 4 8
 x2  x  2

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.

Questions yet to be answered:


Polynomial interpolation of many data points would require a
high degree polynomial, which is not recommended. Then what
other options do we have? 83
Summary
 The interpolating polynomial is unique.
 Different methods can be used to obtain it.
 Newton’s divided difference
 Lagrange interpolation
 Others
 Polynomial interpolation can be sensitive to data.
 BE CAREFUL when high order polynomials are
used.

CISE301_Topic5 84
Summary

When use interpolation?

If the data you have is expected to be of low accuracy, or


the number of data points is too large, regression would
be a best choice.

When the data is of high accuracy and it is required to


estimate the values of the function between the given
data points, then, interpolation is the best choice.

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 )

Idea of using piecewise polynomials

and use a linear function as the interpolating polynomial in


each subinterval. 88
Interpolation: Splines
The idea is further illustrated by the example below where
significant improvement of interpolation can be seen through
comparison between spline and polynomial interpolations of
various orders. The bold black line is the real solution.

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

Application of Lagrange interpolation technique to each


subinterval yields
 x  x2 x  x1
 y1  y2 , x1  x  x2
 x1  x2 x2  x1
 x  x3 x  x2
y ( x)   y2  y3 , x2  x  x3
 x2  x3 x3  x2
 x  x4 x  x3
 y 3  y4 , x3  x  x4
 x3  x4 x4  x3
90
Interpolation: Splines
Example 1. Find the piecewise linear interpolation function for
x  [0 1 2 3], y  [0 1 4 3]

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 x0
 y1  y 2  0  1 x
 x1  x2 x2  x1 0 1 1 0
 x  x3 x  x2 x2 x 1
y ( x)   y2  y3  1 4  3x  2
 x2  x3 x3  x2 1 2 2 1
 x  x4 x  x3 x 3 x2
 y3  y4  4 3  x  6
 x3  x4 x4  x3 23 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

Piecewise linear interpolation


(1) is the simplest form of piecewise polynomial interpolation,
(2) interpolates the data with piecewise linear function,
(3) is a continuous function, but not a smooth one.
92
Interpolation: Splines
The principal drawback of piecewise linear interpolation is
that the derivatives at data points do not exist. To improve
the smoothness, a piecewise quadratic function will be used.
2. Piecewise quadratic 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:

(x1,y1), (x4, y4):


end points

(x2,y2), (x3, y3):


interior knots

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

ai xi2  bi xi  ci  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

yi' ( xi )  2ai xi  bi , i  2, ... ..., n  1

2ai 1 xi  bi 1  2ai xi  bi , 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).

xi 3.0 4.5 7.0 9.0


yi 2.5 1.0 2.5 0.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 x9
 3 3 3
98
Interpolation: Splines
(a) Equal values at interior knots
For first interior knot: x2  4.5

x22 a1  x2b1  c1  y2 (4.5) 2 a1  4.5b1  c1  1.0

The 1st equation: 20.25a1  4.5b1  c1  1.0

x22 a2  x2b2  c2  y2 (4.5) 2 a2  4.5b2  c2  1.0

The 2nd equation 20.25a2  4.5b2  c2  1.0

For second interior knot: x3  7.0

The 3rd equation 49a2  7b2  c2  2.5

The 4th equation 49a3  7b3  c3  2.5


99
Interpolation: Splines
(b) First and last splines pass the end points
For the 1st end point x1  3 x12 a1  x1b1  c1  y1

The 5th equation 9a1  3b1  c1  2.5

For the 2nd end point x4  9 x42 a3  x4b3  c3  y4

The 6th equation 81a3  9b3  c3  0.5

100
Interpolation: Splines
(c) Equal first derivatives at the interior knots.

For the first interior knot x2  4.5 2 x2 a1  b1  2 x2 a2  b2

The 7th equation 9a1  b1  9a2  b2

For the second interior knot x3  7.0 2 x3 a2  b2  2 x3 a3  b3

The 8th equation 14a2  b2  14a3  b3

(d) second derivative at the first point is 0


The 9th equation a1  0
101
Interpolation: Splines
Now we have 8 equations with 8 unknowns which can be
solved from the matrix equation

 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

y( x)  0.64 x 2  6.76 x  18.46, 4.5  x  7.0


y( x)  1.6 x 2  24.6 x  91.3, 7.0  x  9.0

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

v (m/sec) 0 227.04 362.78 517.35 602.97 901.67

105
Interpolation: Splines
Solution:

Since there are 6 data points, 5 piecewise quadratic splines are


needed.
v(t )  a1t 2  b1t  c1 , 0  t  10

v(t)  a 2 t 2  b2 t  c 2 , 10  t  15

v(t)  a3t  b3t  c3 , 15  t  20


2

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

t32 a2  t3b2  c2  v3 , (15) 2 a2  15b2  c2  362.78


t32 a3  t3b3  c3  v3 , (15) 2 a3  15b3  c3  362.78

t 42 a3  t 4b3  c3  v4 , (20) 2 a3  20b3  c3  517.35


t 42 a4  t 4b4  c4  v4 , (20) 2 a4  20b4  c4  517.35
107
Interpolation: Splines
t52 a4  t5b4  c4  v5 , (22.5) 2 a5  22.5b5  c5  602.97

t52 a5  t5b5  c5  v5 , (22.5) 2 a5  22.5b5  c5  602.97

(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

(c) Equal first derivatives at the interior knots.


t2  10 : 2t2 a1  b1  2t2 a2  b2 , 20a1  20a2  b1  b2  0
t3  15 : 2t3a2  b2  2t3a3  b3 , 30a2  30a3  b2  b3  0
108
Interpolation: Splines

t4  20 : 2t4 a3  b3  2t4 a4  b4 , 40a3  40a4  b3  b4  0


t5  22.5 : 2t5 a4  b4  2t5a5  b5 , 45a4  45a5  b4  b5  0

(d) second derivative at the first point is 0


a1  0

So far, we have got 15 equations to be used to calculate


the 15 unknown coefficients in 5 quadratic splines.

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

Solving the matrix equation gives

i ai bi ci

1 0 22.704 0

2 0.8888 4.928 88.88

3 -0.1356 35.66 -141.61

4 1.6048 -33.956 554.55

5 0.20889 28.86 -152.13

111
Interpolation: Splines
Therefore, the piecewise quadratic splines are given by
v(t )  22.704t , 0  t  10

v(t )  0.8888t 2  4.9280t  88.88, 10  t  15

v(t )  0.1356t 2  35.66t  141.61, 15  t  20

v(t )  1.6048t 2  33.956t  554.55, 20  t  22.5

v(t )  0.2089t 2  28.86t  152.13, 22.5  t  30

The velocity at t = 16 sec:


v(16)  0.1356(16) 2  35.66(16)  141.61  394.24 m/sec
112
Interpolation: Splines
Find the acceleration of the rocket at t =16s.
d
a (16)  v(t ) t 16
dt
The quadratic spline valid at t =16 is given by
v(t )  0.1356t 2  35.66t  141.61, 15  t  20,
d d
a(t )  v(t )  (0.1356t 2  35.66t  141.61)
dt dt
a(t )  0.2712t  35.66 15  t  20
a(16)  0.2712(16)  35.66
 31.321 m/s2
113
Interpolation: Splines
3. Idea of a cubic spline
In subinterval i, a cubic spline takes the form of
y ( x)  ai x 3  bi x 2  ci x  d i
The coefficients are to be determined from the conditions
used in a quadratic spline plus
(a) the continuity of 2nd-order derivatives at the internal
knots, and
(b) zero 2nd-order derivatives at the last point.
The cubic spline with zero 2nd-order derivatives at both end points
is called natural cubic spline.
114
Assignment 10
Q. 1. Find the interpolation polynomial for the data given
below by using Newton divided difference method and
estimate the value of y (1.5). Calculate the coefficients
through the working table.

x -1 1 0 -2 2 3
y 1 0 3 -4 2 5

Q.2. Solve Q.1 again by using the Lagrange interpolating


polynomial

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

Q. 4. Solve Q.2 again by using the Lagrange interpolating


polynomial.
116
Assignment 10
Q. 5. Are the following functions quadratic splines? Explain
why or why not?

 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

Q. 7. Redo Q.2 by using quadratic splines. Work out the


matrix equation which determines the coefficients and do
not go further.

Due Date: 27 Nov 2017


118
Determinant of Matrix
For ONLY a 3x3 matrix write down the first
two columns after the third column

 a11 a12 a13   a11 a12 a13  a11 a12


A   a21 a22 a23  a a22 a23  a21 a22
 21
 a31 a32 a33   a31 a32 a33  a31 a32

Sum of products along red arrow


minus sum of products along blue arrow
det  A   a11a22 a33  a12 a23a31  a13a21a32
 a13a22 a31  a11a23a32  a12 a21a33
This technique works only for 3x3 matrices 119

You might also like