MIDTERM
MIDTERM
Intended Learning Outcomes : At the end of this lesson, you should be able to :
1. Find a Interpolating polynomial through a set of points
2. To determine values in between known points using the Lagrange Interpolation.
3. To interpolate values the Newtons Divided Difference Method
4. To determine intermidiate y-values using the quadratic spline
5. To fit a trend line to a given data set using the method of least square
Discussions :
1. Polynomial Interpolation
Let a1 , … , an be fixed numbers and an ≠ 0. The polynomial of the form,
f(x) = a0 + a1 x1 + a2 x2 + … + an xn
Theorem
For a number of points n+1, where (x0, y0), … , (xn, yn) has distinct numbers x0, x1 , …
xn, There is a polynomial of degree n that interpolates on these points.
Illustrative Problem 1:
Find the function f(x) of second degree where f(1) = 3, f(2) = 4, and f(3) = 9.
Solution:
Since f(x) has degree 2, it must be of the form : f(x) = a + bx + cx2 .
At f(1) = 3 : 3 = a +b(1) + c(1)2 = 3 = a + b + c-------------------------E1
At f(2) = 4 : 4 = a +b(2) + c(2)2 = 4 = a + 2b + 4c---------------------E2
2
At f(3) = 9 : 9 = a +b(3) + c(3) = 9 = a + 3b + 9c---------------------E3
Solve the equations E1, E2, and E3 simultaneously
a=6
b = -5
c=2
10
9
8
7
6
5
4
3
2
1
0
0.5 1 1.5 2 2.5 3 3.5
Answer : The function f(x) = 6 -5x+ 2x2 interpolates the three points.
2. Lagrange Interpolation
Usage : To determine values in between known points in a data set
Lagrange interpolating polynomial can be written as
n
f n (x )= Σ Li ( x ) f (xi )
i=
0
n
Π
L ( x )= x−x j
i
j= 0 xi −xj
where : j≠i Π → defined as "product of"
For Example
1st degree : x−x x−x
1
f ( x )= f (x + 0
(
f x )
1 o) x −x 1
x 0 −x 1 1 0
2nd degree :
( x − x )( x − x ) ( x − x )( x − x ) ( x − x )( x − x )
f 2( x )= 1 2 0 1 )+ 0 1
−x )( −x f (xo )+ f x −x )( x −x f (x2)
(x x ) (x 2 ()x ( )
0 1 0 2 1
−x )( x 1−x 2
0 2 0 2 1
nd
3 degree :
( x − x 1 )( x − x 2 )( x − x 3 ) ( x−x 0 )( x−x 2 ) ( x−x 0 )( x−x 1 )( x−x 3 ) x−x ( x−x 0 )( x−x 1 )( f(x )
f( x−x
( x 3))= f (x )+ f (x )+ f ( x2 ))+
3 o 1 2 3
(x 0 −x 1)( x0 −x 2 )(x0 −x 3) (x 1 −x 0)( x1 −x 2 )( x1 −x3 ( x −x )( x −x )( x −x ( x −x )( x −x )( x −x )
) ) 2 0 2 1 2 3 3 0 3 1 3 2
Illustrative Problem 2:
Using the data points shown below estimate the value of y if x = 1.6,
Use the Lagrange third - degree interpolation.
x y = f(x)
x0 = 1 3
x1 = 2 4
x2 = 3 9
x3 = 4.6 18
Solution :
( x − x 1 )( x − x 2 )( x − x 3 ) ( x−x 0 )( x−x 2 ) ( x−x 0 )( x−x 1 )( x−x 3 ) x−x ( x−x 0 )( x−x 1 )(
(f x−x
( x 3))= f (x )+ f(x )
f (x )+ f ( x2 ))+
3 o 1 2 3
(x 0 −x 1)( x0 −x 2 )(x0 −x 3) (x 1 −x 0)( x1 −x 2 )( x1 −x3 ( x2 −x 0 )( x2 −x 1 )( x2 −x3 ( x3 −x 0 )( x3 −x 1 )( x3 −x2 )
) )
( 1. 6−2 )( 1. 6−3 )( 1. 6−4 . 6) (1 . 6−1)(1 .6−3 )( 1. 6−4 . 6) (1 . 6−1)(1 .6−2 )( 1. 6−4 . 6) (1 . 6−1)(1 .6−2 )( 1. 6−3)
f (1 .6 ) = 9+ 18
3 4
3
( 1−2 )( 1−3 )( 1−4 .6 )
+ + (4 . 6−1 )( 4 . 6−2)( 4 . 6−3)
( 2−1 )( 2−3 )( 2−4 . 6) ( 3−1 )( 3−2 )( 3−4 . 6)
f3(1.6) = 0.7 + 3.87692 – 2.025+0.40385 ≈ 2.9558 (answer)
3. Newton Divided Difference Method
Usage : To determine values in between known points in a data set
where
bo =f (xo)
b1 =f ( x1 ,xo )
.
.
.
bn =f ( x n ,xn−1 , . .. ,x1 ,x0 )
.
.
.
nth term
f (xn ,xn−1 ,. .. ,x1 ,x0 )= ( n n−1
f x ,x ,. .. x1)−f ( xn−1 ,xn−2 ,. .. x0)
x n −x o
Illustrative Problem 2:
Using the data points shown below estimate the value of y if x = 1.6,
Use the Newton Divided Difference interpolation.
x y = f(x)
x0 = 1 3
x1 = 2 4
x2 = 3 9
x3 = 4.6 18
Solution :
1. Prepare the table
i x f(x) f(xi, xj) f(xi, xj, xk) f(xi, xj, xk, xl)
0 1 3
1 2 4 4−3
2−1 =1
2 3 9 9−4 5−1
3−2 =5 3−1 =2
3 4.6 18 18−9 5.625−5
=5.625 =0.240385 0.240385−2
4.6−1 =−0.488782
4.6−3 4.6−2
interestingly
f2(1.6) = 3+ 1(1.6-1) + 2(1.6-1)(1.6-2) = 3.12 , quadratic
f1(1.6) = 3+ 1(1.6-1) = 3.6 , linear
4. Quadratic Spline
Usage : To determine values in between known points in a data set using a spline
Consider the data set shown below. We want to draw a series of quadratic curve to link the
points given such that the overall curve is "smooth". There will be three quadratic functions for this
data set. One for each set of adjacent points.
20
x y 20
1 1 10
3 -2 10
6 15 0
0
10 9 0 2 4 6 8 10 12 0 2 4 6 8 10 12
-10 -10
x y
1 1
3 -2
6 15
10 9
Solution :
STEP BY STEP
2.2 "function values at end points are equal to y-values at end points"
At x = 1; a1(1) + b1(1) +c1 = 1
At x = 10; a3(100) + b3(10) +c3= 9
2.3 "the slopes of the functions meeting at an interior point are equal"
y1' = y2'
At x = 3; 2a1(3) + b1 = 2a2(3) + b2
6a1 + b1 - 6a2 – b2 = 0
y2' = y3'
At x = 6; 2a2(6) + b2 = 2a3(6) + b3
12a2 + b2 - 12a3 – b3 = 0
General Form
y = a + bx + e
where :
a = intercept
b = slope
e = error
where :
n ∑ xy−∑ x ∑ y
b= 2
n ∑ x 2 − (∑ x )
a=¯y−b ¯x
Error Analysis
St = Σ(y- y)2
2
St −Sr
r= St
, -1 < r < 1.0 (perfect positive fit) correlation coefficient
Illustrative Problem 4: Fit a straight trend line using the method of least square from the following
data set, and find the trend values. Estimate y when x = 8. Determine the correlation coefficient r.
x y
1 1
3 -2
6 15
10 9
Solution:
1. Populate the table
x y x2 y2 xy
1 1 1 1 1
3 -2 9 4 -6
6 15 36 225 90
10 9 100 81 90
Σ 20 23 146 311 175
n ∑ xy−∑ x ∑ y
b= 2 4
n∑ x2−(∑ x ) (175)−20(23)
=
b = 1.304348 4 (146 ) – 202
a=¯y−b ¯x
= 5.75 – 1.304348(5) = -0.771739
3. Estimate y when x = 8.
y = -0.771739 + 1.304348x (trend line)
y = -0.771739 + 1.304348(8)
y = 9.6630, estimate , Answer
4. Perform Error Analysis
n=4, y= 5.75, a = -0.771739, b =1.304348
x y (y- y)2 (y-a-bx)2
1 1 22.5625 0.2185
3 -2 60.0625 26.4330
6 15 85.5625 63.1334
10 9 10.5625 10.7043
Σ 20 23 178.75 100.4891
St Sr
2
St −Sr
r= St
= (178.75-100.4891)/178.75 =0.437823
r = 0.66168 , correlation coeffient
Self Assessment(Problem Set) :
P1. Find the function f(x) of second degree where f(2) = 3, f(6) = 4, and f(9) = 9.
P2. Using the data points shown below estimate the value of y if x = 7,
Use the Lagrange third - degree interpolation.
x y = f(x)
2 3
6 4
9 9
11 10
P3. Using the data points shown below estimate the value of y if x = 7,
Use the Newton Divided Difference interpolation.
x y = f(x)
2 3
6 4
9 9
11 10
P4. Consider the data set shown below. Obtain the quadratic spline to fit the data set shown below.
Estimate the value of y when x = 7.
x y = f(x)
2 3
6 4
9 9
11 10
P5: Fit a straight line trend using the method of least square from the following data set, and find
the trend values. Estimate y when x = 8. Determine the correlation coefficient r.
x y = f(x)
2 3
6 4
9 9
11 10