Page 169 - Applied Numerical Methods Using MATLAB
P. 169
158 INTERPOLATION AND CURVE FITTING
into Eq. (3.1.3) as
2 2 N
x − x k
l 2 (x) = f m L 2,m (x) = f m (P3.1.1)
x m − x k
m=0 m=0 k =m
Check if the zero of the derivative of this polynomial—that is, the root
of the equation l (x) = 0—is found as
2
(x − x 1 ) + (x − x 2 ) (x − x 2 ) + (x − x 0 )
l (x) = f 0 + f 1
2
(x 0 − x 1 )(x 0 − x 2 ) (x 1 − x 2 )(x 1 − x 0 )
(x − x 0 ) + (x − x 1 )
+ f 2
(x 2 − x 0 )(x 2 − x 1 )
f 0 (2x − x 1 − x 2 )(x 2 − x 1 ) + f 1 (2x − x 2 − x 0 )(x 0 − x 2 )
+ f 2 (2x − x 0 − x 1 )(x 1 − x 0 ) = 0
2
2
2
2
2
2
f 0 (x − x ) + f 1 (x − x ) + f 2 (x − x )
2
1
2
0
0
1
x = x 3 = (P3.1.2)
2{f 0 (x 1 − x 2 ) + f 1 (x 2 − x 0 ) + f 2 (x 0 − x 1 )}
You can use the symbolic computation capability of MATLAB by
typing the following statements into the MATLAB command window:
>>syms x x1 x2 x3 f0 f1 f2
>>L2 = f0*(x - x1)*(x - x2)/(x0 - x1)/(x0 - x2)+...
f1*(x - x2)*(x - x0)/(x1 - x2)/(x1 - x0)+...
f2*(x - x0)*(x - x1)/(x2 - x0)/(x2 - x1)
>>pretty(solve(diff(L2)))
(b) The second-degree Newton polynomial matching the three points
(x 0 ,f 0 ), (x 1 ,f 1 ),and (x 2 ,f 2 ) is Eq. (3.2.4).
n 2 (x) = a 0 + a 1 (x − x 0 ) + a 2 (x − x 0 )(x − x 1 ) (P3.1.3)
where
f 1 − f 0
a 0 = f 0 , a 1 = Df 0 =
x 1 − x 0
f 2 − f 1 f 1 − f 0
−
2 Df 1 − Df 0 x 2 − x 1 x 1 − x 0
a 2 = D f 0 = = (P3.1.4)
x 2 − x 0 x 2 − x 0
Find the zero of the derivative of this polynomial.
(c) From Eq. (P3.1.1) with x 0 =−1,x 1 = 0, and x 2 = 1, find the coeffi-
cients of Lagrange coefficient polynomials L 2,0 (x), L 2,1 (x),and L 2,2 (x).
You had better make use of the routine “lagranp()” for this job.