interpolation methods
TRANSCRIPT
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
11
yy
aa
xx
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Solving for the constants!
12
121
12
21120 &
xxyya
xxyxyxa
−−
=−−
=
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
32
210 xaxaxaay +++=For the four points
313
2121101 xaxaxaay +++=
323
2222102 xaxaxaay +++=
333
2323103 xaxaxaay +++=
343
2424104 xaxaxaay +++=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
In Matrix Form
=
4
3
2
1
3
2
1
0
34
224
33
223
32
222
31
211
1111
yyyy
aaaa
xxxxxxxxxxxx
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
Y x
1 -1
2 0
5 1
16 2
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Solution: System of equations • A third order polynomial is given by:
( ) 34
2321 xaxaxaaxf +++=
( ) 11 4321 =−+−=− aaaaf
( ) 20 1 == af
( ) 51 4321 =+++= aaaaf
( ) 168422 4321 =+++= aaaaf
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
In matrix form
=
−−
16521
8421111100011111
4
3
2
1
aaaa
=
1112
4
3
2
1
aaaa
( ) 322 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 =⇒−+=
( )112
121 xx
xxyyyy −
−−
+=
( )⇒−+= 12102 xxbby
( ) ( )( )12
12112112 xx
yybxxbyy−−
=⇒−+=
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
xxxxbxxbbxf
−−+−+=
10 yb =
12
121 xx
yyb−−
=
13
12
12
23
23
2 xxxxyy
xxyy
b−
−−
−−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Using a table yi xi
y1 x1
y2 x2
y3 x3
13
12
12
23
23
xxxxyy
xxyy
−−−
−−−
12
12
xxyy
−−
23
23
xxyy
−−
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
Y x
1 -1
2 0
5 1
16 2
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Newton’s Method • Newton’s methods defines the polynomial in the
form:
( ) ( ) ( )( )( )( )( )3213
212110
xxxxxxbxxxxbxxbbxf−−−+
−−+−+=
( ) ( ) ( )( )( )( )( )11
11
3
210
−++++++=
xxxbxxbxbbxf
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Newton’s Method Y x
1 1 1 1 -1
4 3 2 0
11 5 1
16 2
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Newton’s Method • Finally:
( ) ( ) ( )( )( )( )( )11
111−++
++++=xxx
xxxxf
( ) ( ) ( ) ( )xxxxxxf −+++++= 3211
( ) 322 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 −+−=
212
11
21
2 yxxxxy
xxxxy
−−
+
−−
=
( ) ( )2121111 xxcxxcy −+−=
( )21
12 xx
yc−
=
( ) ( )2221212 xxcxxcy −+−=
( )12
21 xx
yc−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Two lines added!
212
11
21
2 yxxxxy
xxxxy
−−
+
−−
=
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
xxxxcxxxxc
xxxxcy
−−+−−+
−−=
( )( )( )( )( )( )11313
31212
211111
xxxxcxxxxc
xxxxcy
−−+−−+
−−=
( )( )312121 xxxxcy −−= ( )( )3121
12 xxxx
yc−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Similarly
( )( )1323
31 xxxx
yc−−
=
( )( )3212
23 xxxx
yc−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Finally
323
2
13
1
232
3
12
1
131
3
21
2
yxxxx
xxxx
yxxxx
xxxx
yxxxx
xxxxy
−−
−−
+
−−
−−
+
−−
−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Three parabolas added!!!
323
2
13
1
232
3
12
1
131
3
21
2
yxxxx
xxxx
yxxxx
xxxx
yxxxx
xxxxy
−−
−−
+
−−
−−
+
−−
−−
=
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
Y x
1 -1
2 0
5 1
16 2
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Solution
434
3
24
2
14
1
343
4
23
2
13
1
242
4
32
3
12
1
141
4
31
3
21
2
yxxxx
xxxx
xxxx
yxxxx
xxxx
xxxx
yxxxx
xxxx
xxxx
yxxxx
xxxx
xxxxy
−−
−−
−−
+
−−
−−
−−
+
−−
−−
−−
+
−−
−−
−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Solution
4
3
2
1
121
020
121
212
010
111
202
101
101
212
111
010
yxxx
yxxx
yxxx
yxxxy
−−
−−
++
+
−−
−−
++
+
−−
−−
++
+
−−−
−−−
−−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Solution ( )( )( )
( )( )( )
( )( )( )
( )( )( )4
3
2
1
611
221
2211
621
yxxx
yxxx
yxxx
yxxxy
−++
−−+
+
−−++
−−−
=
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
Solution ( )( )( )
( )( )( )
( )( )( )
( )( )( )166
11
52
21
22
211
16
21
−++
−−+
+
−−++
−−−
=
xxx
xxx
xxx
xxxy
Interpolation Mohammad Tawfik
#WikiCourses http://WikiCourses.WikiSpaces.com
• I will leave it for you to simplify the relation and obtain the same previous polynomial!