You are on page 1of 58

Polynomial Interpolation Polynomial Interpolation

Chapter 14 Chapter 14
Interpolation & Extrapolation
Interpolation: data to be found are within the range of
observed data.
Extrapolation: data to be found are beyond the range of
observation data. (not reliable*)
Interpolation Interpolation
Used to estimate values between data points
Difference from regression -
exactly goes through data points
therefore, no error at data points
The most common method is the polynomial interpolation
Interpolation vs. Regression Interpolation vs. Regression
Same data points, different curve fitting
Given n data points, fit a unique (n-1)
th
- order polynomial
through them
Use polynomial interpolation to determine as
For consistency with MATLAB, use
)
1 n
n
2
3 2 1
x a x a x a a x f

+ + + + = ...
Polynomial Interpolation Polynomial Interpolation
n 1 n
2 n
2
1 n
1
p x p x p x p x f + + + + =


. ) (
Interpolating Polynomials Interpolating Polynomials
First-order second-order third-order
Coefficients of an Interpolating Polynomial Coefficients of an Interpolating Polynomial
Newton and Lagrange polynomials are well-suited for
determining values between points (interpolation)
However, they do not provide a convenient polynomial
of conventional form
Use n data points to determine n coefficients

!
!
!


n n 1 n
2 n
n 2
1 n
n 1 n
n 2 1 n
2 n
2 2
1 n
2 1 2
n 1 1 n
2 n
1 2
1 n
1 1 1
p x p x p x p x f
p x p x p x p x f
p x p x p x p x f
.
/
.
.
) (
) (
) (
n 1 n
2 n
2
1 n
1
p x p x p x p x f !


. ) (
Coefficients of an Interpolating Polynomial Coefficients of an Interpolating Polynomial
Can be solved with any matrix method, but not efficient
There are more efficient methods to find ps
The above equations are notoriously ill-conditioned,
especially for large n
Limit yourself to lower-order polynomials





) (
) (
) (
) (
n
3
2
1
n
3
2
1
n
2 n
n
1 n
n
3
2 n
3
1 n
3
2
2 n
2
1 n
2
1
2 n
1
1 n
1
x f
x f
x f
x f
p
p
p
p
1 x x x
1 x x x
1 x x x
1 x x x
/ /
.
/ 1 / / /
1
.
.
Polynomial Coefficients Polynomial Coefficients
Example use last four points of Table 14.1
4 3
2
2
3
1 1 1
4 3
2
2
3
1 1 1
4 3
2
2
3
1 1 1
4 3
2
2
3
1 1 1
4 3
2
2
3
1
p 500 p 500 p 500 p 457 0 x f 500 x
p 400 p 400 p 400 p 525 0 x f 400 x
p 300 p 300 p 300 p 616 0 x f 300 x
p 250 p 250 p 250 p 675 0 x f 250 x
p x p x p x p x f
+ + + = = =
+ + + = = =
+ + + = = =
+ + + = = =
+ + + =
) ( ) ( ) ( . ) ( ;
) ( ) ( ) ( . ) ( ;
) ( ) ( ) ( . ) ( ;
) ( ) ( ) ( . ) ( ;
) (

457 0
525 0
616 0
675 0
p
p
p
p
1 500 500 500
1 400 400 400
1 300 300 300
1 250 250 250
4
3
2
1
2 3
2 3
2 3
2 3
.
.
.
.
) ( ) (
) ( ) (
) ( ) (
) ( ) (
Vandermonde
Matrices
>> A=[250^3 250^2 250 1; 300^3 300^2 300 1; 400^3 400^2 400 1; 500^3 500^2 500 1]
A =
15625000 62500 250 1
27000000 90000 300 1
64000000 160000 400 1
125000000 250000 500 1
>> b=[0.675; 0.616; 0.525; 0.457]
b =
0.6750
0.6160
0.5250
0.4570
>> format long
>> p = A\b
p =
-0.00000000260000
0.00000427000000
-0.00293700000000
1.18300000000000
>> cond(A)
ans =
9.306535523991324e+009
Vandermonde Matrices Vandermonde Matrices
ill-conditioned matrix
1830000000 1 x 0029370000 0
x 0000042700 0 x 0000000026 0 x f
2 3
. .
. . ) (
+
+ =
Newton Interpolation Newton Interpolation
Use Newtons divided differences of the
functional values
The lower order coefficients b
i
do not change
when the order of interpolation is increased
It is easy to add more data points and try a
higher order polynomial
) ( ) )( (
) )( ( ) ( ) (
1 n 2 1 n
2 1 3 1 2 1 1 n
x x x x x x b
x x x x b x x b b x f


!
.
.
Newton Linear Interpolation Newton Linear Interpolation
) (
) ( ) (
) ( ) (
) ( ) ( ) ( ) (
1
1 2
1 2
1 1
1 2
1 2
1
1 1
x x
x x
x f x f
x f x f
x x
x f x f
x x
x f x f

Start with linear interpolation: f


1
(x) = b
1
+ b
2
(x x
1
)
Similar triangles
Newton linear interpolation formula
Example 1: interpolate e
2
using e
1
and e
5
Example 2: Interpolate e
2
using e
1.5
and e
2.5
) )
) )
)
1
1 2
1 2
1 1
x x
x x
x f x f
x f x f

!
) ) ) 423 36 1
4
7183 2 41 148
7183 2 1 2
1 5
e e
e 2 f
1 5
1
1
.
. .
. !

!
) ) ) 3321 8 5 0
1
4817 4 1825 12
4817 4 5 1 2
5 1 5 2
e e
e 2 f
5 1 5 2
5 1
1
. .
. .
. .
. .
. .
.
!

!
3891 7 e Exact
2
. =
Newton Linear Interpolation Newton Linear Interpolation
Newton Linear Interpolation Newton Linear Interpolation
ccuracy of Interpolation Accuracy of Interpolation
Small interval (x provides a better estimate
Linear estimates
of ln(2)
Logarithmic function
Quadratic interpolation need three points
Use the parabola
This is the same as
) ) ) )
2 1 3 1 2 1 2
x x x x b x x b b x f + + =

=
=
+ =
+ + =
3 3
2 3 1 3 2 2
2 1 3 1 2 1 1
2
3 2 1 2
b a
x b x b b a
x x b x b b a
x a x a a x f ) (
Quadratic Interpolation Quadratic Interpolation
where
To get the coefficients bs
1) Set x = x
1
, get b
1
= f(x
1
)
2) Use b
1
and set x = x
2
to get b
2
) ) ) ) )
1 1 2 1 1 1 3 1 1 2 1 1 2
x f b x x x x b x x b b x f = = + + =
) ) ) ) ) )
) )
1 2
1 2
2
2 2 2 1 2 3 1 2 2 1 2 2
x x
x f x f
b
x f x x x x b x x b x f x f

=
= + + =
Quadratic Interpolation Quadratic Interpolation
) ) ) )
2 1 3 1 2 1 2
x x x x b x x b b x f + + =
) )
) )
) ) ) )
) ) ) )
1 3
1 2
1 2
2 3
2 3
3
3 2 3 1 3 3 1 3
1 2
1 2
1 3 2
x x
x x
x f x f
x x
x f x f
b
x f x x x x b x x
x x
x f x f
x f x f

=
= +

+ =
b
1
is a constant (0th order)
b
2
gives slope (finite difference)
b
3
gives curvature (difference of finite differences)
Quadratic Interpolation Quadratic Interpolation
3) Use b
1
and b
2
, and set x = x
3
to get b
3
Example: interpolate e
2
using e
1
, e
3
, and e
5
)
)
)

41 148 x f 5 x
086 20 x f 3 x
7183 2 x f 1 x
3 3
2 2
1 1

! !
! !
! !
.
.
.
870 13
1 5
1 3
e e
3 5
e e
b ; 6836 8
1 3
e e
b ; 7183 2 b
1 3 3 5
3
1 3
2 1
. . . !

! !

! !
) ) ) ) 4681 2 3 2 1 2 870 13 1 2 6836 8 7183 2 2 f
2
. * . * . . = + + =
3891 7 e xact
2
. !
Hand Calculation Example Hand Calculation Example
Example: interpolate e
2
using e
1
, e
1.5
, and e
2.5
)
)
)

1825 12 x f 5 2 x
4817 4 x f 5 1 x
7183 2 x f 1 x
3 3
2 2
1 1

! !
! !
! !
. .
. .
.
7827 2
1 5 2
1 5 1
e e
5 1 5 2
e e
b ; 5268 3
1 5 1
e e
b ; 7183 2 b
1 5 1 5 1 5 2
3
1 5 1
2 1
.
.
. . .
.
.
.
. . .
.
!

! !

! !
) ) ) ) 6365 7 5 1 2 1 2 7827 2 1 2 5268 3 7183 2 2 f
2
. . * . * . . = + + =
3891 7 e xact
2
. !
Example Example use different x use different x
ii
Quadratic Interpolation Quadratic Interpolation
Quadratic Interpolation Quadratic Interpolation
Order of Interpolation Order of Interpolation
Higher-order interpolation improves the estimate
Linear, quadratic and cubic estimates of ln(2)
Logarithmic function
General form for Newtons interpolating polynomials
Bracketed functions are finite differences
) ) ) )
) ) ) ) x x x x x x x x b
x x x x b x x b b x f
1 n 3 2 1 n
2 1 3 1 2 1 1 n


!
. .
.
)
. J
. J
. J
1 2 1 n n n
1 2 3 3
1 2 2
1 1
x x x x f b
x x x f b
x x f b
x f b
, , , ,
, ,
,
.
/

!
!
!
!
Newtons Interpolating Polynomials Newtons Interpolating Polynomials
First finite difference
Second finite difference
The difference of two finite differences
. J
) )
j i
j i
j i
x x
x f x f
x x f

! ,
. J
. J . J
k i
k j j i
k j i
x x
x x f x x f
x x x f

=
, ,
, ,
Newtons Divided Differences Newtons Divided Differences
The n
th
finite difference
. J
. J . J
1 n
1 2 2 n 1 n 2 3 1 n n
1 2 1 n n
x x
x x x x f x x x x f
x x x x f

, , , , , , , ,
, , , ,
- -
-
An iterative procedure
1. Evaluate all first-order finite differences; save f (x
1
) for b
1
2. Evaluate second-order from firsts; save f [x
2
, x
1
] for b
2
3. Continue to n
th
-order, saving needed ones
Newtons Divided Differences Newtons Divided Differences
Newton Interpolation Newton Interpolation
. J
. J
. J . J
. J
. J . J
. J
. J . J
. J
. J . J
1 5
1 2 3 4 2 3 4 5
1 2 3 4 5 5
1 4
1 2 3 2 3 4
1 2 3 4 4
1 3
1 2 2 3
1 2 3 3
1 2
1 2
1 2 2
1 1 1
1 n 1 n 2 1 3 1 2 1 1 n
x x
x x x x f x x x x f
x x x x x f b
x x
x x x f x x x f
x x x x f b
x x
x x f x x f
x x x f b
x x
x f x f
x x f b
x f x f b
x x x x b x x x x b x x b b x f

= =

= =

= =

= =
= =
+ + + + =

, , , , , ,
, , , ,
, , , ,
, , ,
, ,
, ,
,
) (
) ( ) ( ) )( ( ) ( ) ( . .
No need to solve a system of simultaneous equations
Spacing may be non-uniform and x
i
may be in arbitrary order
. J . J . J . J
. J . J . J . J
. J . J . J . J
. J . J . J
. J . J
. J
) (
, ) (
, , , ) (
, , , , , , ) (
, , , , , , , , , , ) (
, , , , , , , , , , ) (
, , , , , , , ) (
6 6
5 6 5 5
4 5 6 4 5 4 4
3 4 5 6 3 4 5 3 4 3 3
2 3 4 5 6 2 3 4 5 2 3 4 2 3 2 2
1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 1
i 4 i i 3 i i 1 i 2 i i 1 i i i i
x f x 6
x x f x f x 5
x x x f x x f x f x 4
x x x x f x x x f x x f x f x 3
x x x x x f x x x x f x x x f x x f x f x 2
x x x x x f x x x x f x x x f x x f x f x 1
x x f x x f x x x f x x f x f y x i . .
+ + + + +
=
Newton Interpolation Newton Interpolation
. J
. J . J
1 n
1 2 2 n 1 n 1 3 1 n n
1 2 1 n n n
1 n 1 n 2 1 3 1 2 1 1 n
x x
x x x x f x x x x f
x x x x f b
x x x x b x x x x b x x b b x f

= =
+ + + + =


, , , , , , ,
, , ,
) ( ) ( ) )( ( ) ( ) (
,
,
. .
. .
.
Use the top element of each column
(= b
n
) to evaluate the interpolated
functional value f(x)
First Second Third Fourth
Percentage Relative Error Percentage Relative Error
elative error decreases
with increasing order of the
interpolating polynomial
The error is also sensitive to
the position and sequence of
the original data
(x
1
, x
2
, x
3
, x
4
, , x
n
)
Hand Calculations Hand Calculations
Newton Interpolation Newton Interpolation
) , , , ( 3 4 1 0 ) x , x , x , (x using 2 x at e f(x) stimate
4 3 2 1
x
! ! !
936187 5 4 x 1 x x 571970 1 1 x x 893752 3 x 718282 1 1 2 f
22407 12 1 x x 893752 3 x 718282 1 1 2 f
3
2
. ) )( ( . ) ( . . ) (
. ) ( . . ) (
! !
! !
. J . J . J
08554 20 3 4
4 3 x
51261 34 59815 54 4 3
1 3 x 1 4 x
609662 8 29329 17 718282 2 1 2
0 3 x 0 4 x 0 1 x
571970 1 893752 3 718282 1 000000 1 0 1
x x x x f x x x f x x f x f x i
i 1 i 2 i 3 i i 1 i 2 i i 1 i i i
.
. .
. . .
. . . .
, , , , , , ) (
= (
= ( = (
= ( = ( = (
+ + + + + +
Error for Newtons interpolating polynomial
Estimate from
The leading term in the truncated polynomial
Similar to the truncation error in a Taylor series
. J ) ) )
n 2 1 1 1 n n 1 n n
x x x x x x x x x x f R =
+
. - , , , ,
Error Estimate Error Estimate
Modified M Modified M- -File: File: yint may be evaluated at multiple points
>> x = [0 1 4 3 1.5 2.5]
x =
0 1.0000 4.0000 3.0000 1.5000 2.5000
>> y = exp(x)
y =
1.0000 2.7183 54.5982 20.0855 4.4817 12.1825
>> xx = 0:0.1:4; yy=exp(xx);
>> [b, yint] = Newtint2(x, y, xx)
b =
1.0000 1.7183 3.8938 1.5720 0.3312 0.0697
2.7183 17.2933 8.6097 2.0687 0.5055 0
54.5982 34.5126 9.6440 2.8270 0 0
20.0855 10.4026 5.4035 0 0 0
4.4817 7.7008 0 0 0 0
12.1825 0 0 0 0 0
yint =
Columns 1 through 8
1.0000 1.1355 1.2670 1.4000 1.5394 1.6893 1.8536 2.0356
Columns 9 through 16
2.2384 2.4651 2.7183 3.0008 3.3153 3.6649 4.0525 4.4817
Columns 17 through 24
4.9561 5.4801 6.0584 6.6964 7.4003 8.1770 9.0343 9.9809
Columns 25 through 32
11.0266 12.1825 13.4606 14.8744 16.4387 18.1698 20.0855 22.2054
Columns 33 through 40
24.5506 27.1441 30.0107 33.1774 36.6729 40.5284 44.7770 49.4543
Column 41
54.5982
>> H = plot(x,y,'mo',xx,yy,'r',xx,yint,'bx'); set(H,'LineWidth',3);
Newton Interpolating Polynomial Newton Interpolating Polynomial
Table
Coefficients of
Newton interpolating
polynomial
Newton Interpolation Polynomial Newton Interpolation Polynomial
f(x) = e
x
,
Interpolation at [0 1 4 3 1.5 2.5]
Lagrange Interpolating Polynomials Lagrange Interpolating Polynomials
Give the same result as the Newtons polynomials,
but different approach
) ( ) )( ( ) )( (
) ( ) )( ( ) )( (
) (
) (
) (
) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) (
n k 1 i i 1 i i 2 i 1 i
n 1 i 1 i 2 1
i i
i
n
i j
1 j
j i
j
i
i
n
1 i
i n n 2 2 1 1 1 n
x x x x x x x x x x
x x x x x x x x x x
x P
x P
x x
x x
x L
x f x L x f x L x f x L x f x L x f


=
=

=
= + + + =
+
+
=
=
=

. .
. . . .
.
ij j i
j i
i i
i i
i i
x L
0 x L i j
1
x P
x P
x L i ; j
Note H =

= =
= = =
) (
) ( ;
) (
) (
) (
:
Lagrange Interpolation Lagrange Interpolation
1st-order Lagrange polynomial
Second-order Lagrange polynomial
Third-order Lagrange polynomial
) ( ) ( ) ( ) ( ) ( ) (
2
1 2
1
1
2 1
2
2 2 1 1 1
x f
x x
x x
x f
x x
x x
x f x x f x f

! !
) (
) )( (
) )( (
) (
) )( (
) )( (
) (
) )( (
) )( (
) (
3
2 3 1 3
2 1
2
3 2 1 2
3 1
1
3 1 2 1
3 2
2
x f
x x x x
x x x x
x f
x x x x
x x x x
x f
x x x x
x x x x
x f


+


+


=
) (
) )( )( (
) )( )( (
) (
) )( )( (
) )( )( (
) (
) )( )( (
) )( )( (
) (
) )( )( (
) )( )( (
) (
4
3 4 2 4 1 4
3 2 1
3
4 3 2 3 1 3
4 2 1
2
4 2 3 2 1 2
4 3 1
1
4 1 3 1 2 1
4 3 2
4
x f
x x x x x x
x x x x x x
x f
x x x x x x
x x x x x x
x f
x x x x x x
x x x x x x
x f
x x x x x x
x x x x x x
x f



!
Linear Lagrange Interpolation Linear Lagrange Interpolation
Both L
1
(x) and L
2
(x) are straight lines
Quadratic Lagrange Interpolation Quadratic Lagrange Interpolation
L
2
(x)f(x
2
)
L
3
(x)f(x
3
)
L
1
(x)f(x
1
)
x
1
x
2
x
3
f(x) = e
x
Interpolation at [0 4]
First First- -order Lagrange interpolation order Lagrange interpolation
f(x) = e
x
,
Interpolation at [0 1 4]
Second Second- -order Lagrange interpolation order Lagrange interpolation
f(x) = e
x
,
Interpolation at [0 1 4 3]
Third Third- -order Lagrange interpolation order Lagrange interpolation
Example: Lagrange Interpolation Example: Lagrange Interpolation
Estimate f(x) = exp(x) at x = 2 using (x
0
, x
1
, x
2
, x
3
) = (0,1,4,3)
second-order: (x
1
, x
2
, x
3
) = (0,1,4)
third order: (x
1
, x
2
, x
3
, x
4
) = (0,1,4,3)
224067 12 5982 54
1 4 0 4
1 2 0 2
71828 1
4 1 0 1
4 2 0 2
0 1
4 0 1 0
4 2 1 2
2 f
4 f
1 4 0 4
1 x 0 x
1 f
4 1 0 1
4 x 0 x
0 f
4 0 1 0
4 x 1 x
x f
2
2
. ) . (
) )( (
) )( (
) . (
) )( (
) )( (
) . (
) )( (
) )( (
) (
) (
) )( (
) )( (
) (
) )( (
) )( (
) (
) )( (
) )( (
) (
=


+


+


=


+


+


=
936187 5 08554 20
6
4
5982 54
12
2
71828 2
6
4
0 1
12
2
2 f
3 f
4 3 1 3 0 3
4 x 1 x 0 x
4 f
3 4 1 4 0 4
3 x 1 x 0 x
1 f
3 1 4 1 0 1
3 x 4 x 0 x
0 f
3 0 4 0 1 0
3 x 4 x 1 x
x f
3
3
. ) . ( ) . ( ) . ( ) . ( ) (
) (
) )( )( (
) )( )( (
) (
) )( )( (
) )( )( (
) (
) )( )( (
) )( )( (
) (
) )( )( (
) )( )( (
) (
=

+ +

=


+


+


+


=
Coefficients of Lagrange Polynomial Coefficients of Lagrange Polynomial
Save the coefficients of Lagrange polynomial
Evaluate the interpolated values at multiple locations
Evaluation of Interpolated Values Evaluation of Interpolated Values
x=[0 4]
x =
0 4
y=exp(x)
y =
1.0000 54.5982
c=Lagrange_coef(x,y)
c =
-0.2500 13.6495
t=2; p=Lagrange_eval(t,x,c)
p =
27.7991
x=[0 1 4 3]
x =
0 1 4 3
y=exp(x)
y =
1.0000 2.7183 54.5982 20.0855
c=Lagrange_coef(x,y)
c =
-0.0833 0.4530 4.5498 -3.3476
t=2; p=Lagrange_eval(t,x,c)
p =
5.9362
x=[0 1 4]
x =
0 1 4
y=exp(x)
y =
1.0000 2.7183 54.5982
c=Lagrange_coef(x,y)
c =
0.2500 -0.9061 4.5498
t=2; p=Lagrange_eval(t,x,c)
p =
12.2241
First-order
Second-order
Third-order
Exact solution
e
2
= 7.389056
Lagrange Interpolation Lagrange Interpolation
Very convenient for the same abscissas but
different y
i
(e.g., measurements always taken
using the same independent variables x
i
)
L
k
(x) need to be computed only once
However, it is less convenient when additional
data may be added
. J . J . J
. J . J . J
. J . J . J . J
1 n 1 n n n 2 2 1 1
n n 2 2 1 1
n n 2 2 1 1
y , x , y , x , , y , x , y , x : 2 new
z , x , , z , x , z , x : 1 new
y , x , , y , x , y , x : original
+ +
. .
. .
. .
Inverse Interpolation Inverse Interpolation
Given xs and f(x)s interpolation let us get new f(x)
from new x
What about new x from new f(x)?
Example: f(x) = 1/x
1. Switch x and f(x) and do new interpolation. However,
non-uniform spacing in [x vs. f(x)] often leads to
oscillations in the resulting interpolating polynomial
2. Fit an n
th
-order polynomial to the original data [f(x)
vs. x], then use root-finding techniques to find x.
Extrapolation Extrapolation
Extrapolation
should be avoided
whenever possible
Use of a seventh-order polynomial to make a prediction of U.S.
population in 2000 based on data from 1920 through 1990
Reasonable to use interpolation, but not the extrapolation
Dangers of Extrapolation Dangers of Extrapolation
Difficulties with Polynomial Interpolation Difficulties with Polynomial Interpolation
Humped and Flat Data Humped and Flat Data
2
x 25 1
1
) x ( f
+
=
Runges
function
Runges function Runges function
x2=-1:0.2:1
x2 =
Columns 1 through 7
-1.0000 -0.8000 -0.6000 -0.4000 -0.2000 0 0.2000
Columns 8 through 11
0.4000 0.6000 0.8000 1.0000
y2=1./(1+25*x2.^2)
y2 =
Columns 1 through 7
0.0385 0.0588 0.1000 0.2000 0.5000 1.0000 0.5000
Columns 8 through 11
0.2000 0.1000 0.0588 0.0385
c=Lagrange_coef(x2,y2)
c =
Columns 1 through 7
0.1035 -1.5830 12.1102 -64.5875 282.5702 -678.1684 282.5702
Columns 8 through 11
-64.5875 12.1102 -1.5830 0.1035
x=-1:0.02:1; y=1./(1+25*x.^2);
t=x; p=Lagrange_eval(t,x2,c);
H=plot(x,y,'r',t,p,'b-',x2,y2,'mo');
set(H,'LineWidth',2.5)
print -djpeg075 poly5.jpg
Oscillations Oscillations
2
x 25 1
1
) x ( f

!
MATLAB Functions:
polyfit and polyval
>> x = linspace(-1,1,5); y = 1./(1+25*x.^2)
>> xx = linspace(-1,1); p = polyfit(x,y,4)
p =
3.3156 0.0000 -4.2772 0.0000 1.0000
>> y4 = polyval(p,xx);
>> yr = 1./(1+25*xx.^2);
>> H=plot(x,y,'o',xx,y4,xx,yr,'--')
>> x=linspace(-1,1,11); y = 1./(1+25*x.^2)
y =
Columns 1 through 8
0.0385 0.0588 0.1000 0.2000 0.5000 1.0000 0.5000 0.2000
Columns 9 through 11
0.1000 0.0588 0.0385
>> p = polyfit(x,y,10)
p =
Columns 1 through 8
-220.9417 0.0000 494.9095 -0.0000 -381.4338 0.0000 123.3597 -0.0000
Columns 9 through 11
-16.8552 0.0000 1.0000
>> y10 = polyval(p,xx);
>> H = plot(x,y,'o',xx,y10,xx,yr,'--')
>> set(H,'LineWidth',3,'MarkerSize',12)
>> print -djpeg Fig14_13.jpg
4
th
-order polynomial
10
th
-order polynomial
Runges Function with polynomial fit Runges Function with polynomial fit
4
th
-order 10
th
-order
[x,y]=example
x =
Columns 1 through 7
0 0.2000 0.8000 1.0000 1.2000 1.9000 2.0000
Columns 8 through 10
2.1000 2.9500 3.0000
y =
Columns 1 through 7
0.0100 0.2200 0.7600 1.0300 1.1800 1.9400 2.0100
Columns 8 through 10
2.0800 2.9000 2.9500
c=Lagrange_coef(x,y)
c =
Columns 1 through 7
-0.0007 0.0512 -2.4384 8.3366 -7.7423 37.5192 -61.2208
Columns 8 through 10
26.4741 -1.1493 0.8958
t=0:0.05:3; p=Lagrange_eval(t,x,c);
H=plot(x,y,'ro',t,p,'b',x,x,'m');
set(H,'LineWidth',2.5); print -djpeg075 poly4.jpg
function [x, y] = example
x = [0.00 0.20 0.80 1.00 1.20 1.90 2.00 2.10 2.95 3.00];
y = [0.01 0.22 0.76 1.03 1.18 1.94 2.01 2.08 2.90 2.95];
Noisy
straight
line
Noisy straight line
CVEN 302 CVEN 302- -501 501
Homework No. 10 Homework No. 10
Chapter 14
Problem 14.1(15) 14.3(15), 14.5 (20)(Hand Calculation)
Problem 14.8 (20)(Hand Calculation and MATLAB
program)
Chapter 15
Problems 15.2 (20), 15.3 (20) (Hand Calculations)
Due on Wednesday 10/29/2008 at the beginning Due on Wednesday 10/29/2008 at the beginning
of the period of the period

You might also like