Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Interpolation/Curve Fitting
Mohammad Tawfik
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Objectives
• Understanding the difference between
regression and interpolation
• Knowing how to “best fit” a polynomial into
a set of data
• Knowing how to use a polynomial to
interpolate data
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Measured Data
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Polynomial Fit!
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Line Fit!
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Which is better?
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Curve Fitting
• If the data measured is of high accuracy
and it is required to estimate the values of
the function between the given points,
then, polynomial interpolation is the best
choice.
• If the measurements are expected to be of
low accuracy (Real life data), or the
number of measured points is too large,
regression would be the best choice.
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Interpolation
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Why Interpolation?
• When the accuracy of your measurements
are ensured
• When you have discrete values for a
function (numerical solutions, digital
systems, etc …)
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Acquired Data
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
But, how to get the equation of a
function that passes by all the
data you have!
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Equation of a Line: Revision
xaay 10 +=
If you have two points
1101 xaay +=
2102 xaay += 





=












2
1
1
0
2
1
1
1
y
y
a
a
x
x
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solving for the constants!
12
12
1
12
2112
0 &
xx
yy
a
xx
yxyx
a
−
−
=
−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
What if I have more than two
points?
• We may fit a
polynomial of order
one less that the
number of points we
have. i.e. four points
give third order
polynomial.
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Third-Order Polynomial
3
3
2
210 xaxaxaay +++=
For the four points
3
13
2
121101 xaxaxaay +++=
3
23
2
222102 xaxaxaay +++=
3
33
2
323103 xaxaxaay +++=
3
43
2
424104 xaxaxaay +++=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
In Matrix Form














=




























4
3
2
1
3
2
1
0
3
4
2
24
3
3
2
23
3
2
2
22
3
1
2
11
1
1
1
1
y
y
y
y
a
a
a
a
xxx
xxx
xxx
xxx
Solve the above equation for the constants of the polynomial.
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Find a 3rd order
polynomial to
interpolate the
function described by
the given points
Yx
1-1
20
51
162
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution: System of equations
• A third order polynomial is given by:
( ) 3
4
2
321 xaxaxaaxf +++=
( ) 11 4321 =−+−=− aaaaf
( ) 20 1 == af
( ) 51 4321 =+++= aaaaf
( ) 168422 4321 =+++= aaaaf
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
In matrix form














=

























 −−
16
5
2
1
8421
1111
0001
1111
4
3
2
1
a
a
a
a














=














1
1
1
2
4
3
2
1
a
a
a
a
( ) 32
2 xxxxf +++=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Newton's Interpolation
Polynomial
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Newton’s Method
• In the previous procedure, we needed to solve a
system of linear equations for the unknown
constants.
• This method suggests that we may just proceed
with the values of x & y we have to get the
constants without setting a set of equations
• The method is similar to Taylor’s expansion
without differentiation!
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
For the two points
( )110 xxbby −+=
( ) 0111101 byxxbby =⇒−+=
( )1
12
12
1 xx
xx
yy
yy −





−
−
+=
( )⇒−+= 12102 xxbby
( ) ( )
( )12
12
112112
xx
yy
bxxbyy
−
−
=⇒−+=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Homework
• Show that the polynomial obtained by
solving a set of equations is equivalent to
that obtained by Newton method
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
For the three points
( ) ( )
( )( )213
121
xxxxb
xxbbxf
−−+
−+=
10 yb =
12
12
1
xx
yy
b
−
−
=
13
12
12
23
23
2
xx
xx
yy
xx
yy
b
−
−
−
−
−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Using a table
yixi
y1x1
y2x2
y3x3
13
12
12
23
23
xx
xx
yy
xx
yy
−
−
−
−
−
−
12
12
xx
yy
−
−
23
23
xx
yy
−
−
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
In General
• Newton’s Interpolation is performed for an
nth order polynomial as follows
( ) ( ) ( )( )
( ) ( )nn xxxxb
xxxxbxxbbxf
−−++
−−+−+=
...... 1
212110
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Find a 3rd order
polynomial to
interpolate the
function described by
the given points using
Newton’s method
Yx
1-1
20
51
162
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Newton’s Method
• Newton’s methods defines the polynomial in the
form:
( ) ( ) ( )( )
( )( )( )3213
212110
xxxxxxb
xxxxbxxbbxf
−−−+
−−+−+=
( ) ( ) ( )( )
( )( )( )11
11
3
210
−++
++++=
xxxb
xxbxbbxf
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Newton’s Method
Yx
1111-1
4320
1151
162
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Newton’s Method
• Finally:
( ) ( ) ( )( )
( )( )( )11
111
−++
++++=
xxx
xxxxf
( ) ( ) ( ) ( )xxxxxxf −+++++= 32
11
( ) 32
2 xxxxf +++=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Advantage of Newton’s Method
• The main advantage of Newton’s method
is that you do not need to invert a matrix!
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Interpolation
Lagrange Interpolation Polynomial
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Lagrange Method
• First, we learned that a polynomial can
pass by the points by using a simple
polynomial with (n-1) terms.
• Then, we learned a way that “looks like”
the Taylor expansion (Newton’s method)
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Lagrange Method (cont’d)
• Now, we will use polynomials that are zero
at all points except the one we are
evaluating at, but, in an easier form!
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
For the two points
( ) ( )2211 xxcxxcy −+−=
2
12
1
1
21
2
y
xx
xx
y
xx
xx
y 





−
−
+





−
−
=
( ) ( )2121111 xxcxxcy −+−=
( )21
1
2
xx
y
c
−
=
( ) ( )2221212 xxcxxcy −+−=
( )12
2
1
xx
y
c
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Two lines added!
2
12
1
1
21
2
y
xx
xx
y
xx
xx
y 





−
−
+





−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Homework
• Show that the polynomial obtained by
solving a set of equations is equivalent to
that obtained by Lagrange method
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
For the three points
( )( )
( )( )
( )( )133
322
211
xxxxc
xxxxc
xxxxcy
−−+
−−+
−−=
( )( )
( )( )
( )( )11313
31212
211111
xxxxc
xxxxc
xxxxcy
−−+
−−+
−−=
( )( )312121 xxxxcy −−= ( )( )3121
1
2
xxxx
y
c
−−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Similarly
( )( )1323
3
1
xxxx
y
c
−−
=
( )( )3212
2
3
xxxx
y
c
−−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Finally
3
23
2
13
1
2
32
3
12
1
1
31
3
21
2
y
xx
xx
xx
xx
y
xx
xx
xx
xx
y
xx
xx
xx
xx
y






−
−






−
−
+






−
−






−
−
+






−
−






−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Three parabolas added!!!
3
23
2
13
1
2
32
3
12
1
1
31
3
21
2
y
xx
xx
xx
xx
y
xx
xx
xx
xx
y
xx
xx
xx
xx
y






−
−






−
−
+






−
−






−
−
+






−
−






−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Example
• Find a 3rd order
polynomial to
interpolate the
function described by
the given points using
Lagrange’s method
Yx
1-1
20
51
162
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
4
34
3
24
2
14
1
3
43
4
23
2
13
1
2
42
4
32
3
12
1
1
41
4
31
3
21
2
y
xx
xx
xx
xx
xx
xx
y
xx
xx
xx
xx
xx
xx
y
xx
xx
xx
xx
xx
xx
y
xx
xx
xx
xx
xx
xx
y






−
−






−
−






−
−
+






−
−






−
−






−
−
+






−
−






−
−






−
−
+






−
−






−
−






−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
4
3
2
1
12
1
02
0
12
1
21
2
01
0
11
1
20
2
10
1
10
1
21
2
11
1
01
0
y
xxx
y
xxx
y
xxx
y
xxx
y






−
−






−
−






+
+
+






−
−






−
−






+
+
+






−
−






−
−






+
+
+






−−
−






−−
−






−−
−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
( )( )( )
( )( )( )
( )( )( )
( )( )( )
4
3
2
1
6
11
2
21
2
211
6
21
y
xxx
y
xxx
y
xxx
y
xxx
y
−+
+
−
−+
+
−−+
+
−
−−
=
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
Solution
( )( )( )
( )( )( )
( )( )( )
( )( )( )16
6
11
5
2
21
2
2
211
1
6
21
−+
+
−
−+
+
−−+
+
−
−−
=
xxx
xxx
xxx
xxx
y
Interpolation
Mohammad Tawfik
#WikiCourses
http://WikiCourses.WikiSpaces.com
• I will leave it for you to simplify the relation
and obtain the same previous polynomial!

Interpolation Methods