Sei sulla pagina 1di 8

Jim Lambers

MAT 460/560
Fall Semester 2009-10
Homework Assignment 8 Solution

Section 3.2
1. Write a MATLAB program that uses Newton’s interpolatory divided-difference formula to
construct interpolating polynomials of degree one, two, and three for the following data.
Approximate the specified value using each of the polynomials. Hint: the Lecture 9 Notes
will be helpful.

(a) 𝑓 (8.4) if 𝑓 (8.1) = 16.94410, 𝑓 (8.3) = 17.56492, 𝑓 (8.6) = 18.50515, 𝑓 (8.7) = 18.82091
Solution The following MATLAB function computes the coefficients of the Newton form
of all three interpolating polynomials 𝑝1 (𝑥), 𝑝2 (𝑥) and 𝑝3 (𝑥) by computing the necessary
divided differences, and then evaluates the polynomials at 𝑥 = 8.4.
% this function computes the interpolating polynomials
% for the given data, x and y, using Newton’s interpolatory
% divided-difference formula. The polynomials of degree
% 1, 2, ..., n are computed, where n is one less than the
% number of data points. The polynomials are then evaluated
% at x0.
function hw2prob321(x,y,x0)
% n is the maximum degree possible with this data
n=length(y)-1;
% initialize divided-difference table
d=y;
for i=1:n,
% compute divided differences, overwriting those
% we don’t need
for j=n+1:-1:i+1,
d(j)=(d(j)-d(j-1))/(x(j)-x(j-i));
end
% use nested multiplication to evaluate the
% polynomial at x0
y0=d(i+1);
for j=i:-1:1,
y0=d(j)+(x0-x(j))*y0;
end

1
% display coefficients of Newton form of interpolating
% polynomial, and the value at x0
disp(sprintf(’Degree %d:’,i))
Coefficients=d(1:i+1)
Value=y0
end
In the following MATLAB session, we use this function with the given data.
>> x=[ 8.1; 8.3; 8.6; 8.7 ];
>> y=[ 16.94410; 17.56492; 18.50515; 18.82091 ];
>> hw2prob321(x,y,8.4)
Degree 1:

Coefficients =

16.9441
3.1041

Value =

17.8753

Degree 2:

Coefficients =

16.9441
3.1041
0.0600

Value =

17.8771

Degree 3:

Coefficients =

16.9441
3.1041

2
0.0600
-0.0021

Value =

17.8771
From the above coefficients, we see that the interpolating polynomials are

𝑝1 (𝑥) = 16.9441 + 3.1041(𝑥 − 8.1)


𝑝2 (𝑥) = 𝑝1 (𝑥) + 0.06(𝑥 − 8.1)(𝑥 − 8.3)
𝑝3 (𝑥) = 𝑝2 (𝑥) − 0.0021(𝑥 − 8.1)(𝑥 − 8.3)(𝑥 − 8.6)

and their values at 𝑥 = 8.4 are

𝑝1 (8.4) = 17.8753, 𝑝2 (8.4) = 17.8771, 𝑝3 (8.4) = 17.8771.

(b) 𝑓 (0.9) if 𝑓 (0.6) = −0.17694460, 𝑓 (0.7) = 0.01375227, 𝑓 (0.8) = 0.22363362, 𝑓 (1.0) =


0.65809197
Solution In the following MATLAB session, we use the function hw2prob321 from part
(a) with the given data and obtain
>> x=[ 0.6; 0.7; 0.8; 1.0 ];
>> y=[ -0.17694460; 0.01375227; 0.22363362; 0.65809197 ];
>> hw2prob321(x,y,0.9)
Degree 1:

Coefficients =

-0.1769
1.9070

Value =

0.3951

Degree 2:

Coefficients =

-0.1769

3
1.9070
0.9592

Value =

0.4527

Degree 3:

Coefficients =

-0.1769
1.9070
0.9592
-1.7857

Value =

0.4420
From the above coefficients, we see that the interpolating polynomials are

𝑝1 (𝑥) = −0.1769 + 1.9070(𝑥 − 0.6)


𝑝2 (𝑥) = 𝑝1 (𝑥) + 0.9592(𝑥 − 0.6)(𝑥 − 0.8)
𝑝3 (𝑥) = 𝑝2 (𝑥) − 1.7857(𝑥 − 0.6)(𝑥 − 0.7)(𝑥 − 0.9)

and their values at 𝑥 = 0.9 are

𝑝1 (8.4) = 0.3951, 𝑝2 (8.4) = 0.4527, 𝑝3 (8.4) = 0.4420.

9. (a) Approximate 𝑓 (0.05) using the following data and the Newton forward divided-difference
formula:
𝑥 0.0 0.2 0.4 0.6 0.8
𝑓 (𝑥) 1.00000 1.22140 1.49182 1.82212 2.22554
Solution Recall the Newton forward-difference formula,
𝑛 ( )
∑ 𝑠
𝑝𝑛 (𝑥) = 𝑓 [𝑥0 ] + Δ𝑘 𝑓 (𝑥0 ).
𝑘
𝑘=1

4
Since the spacing ℎ is (0.8 − 0.0)/4 = 0.2, we have 𝑠 = (𝑥 − 0.0)/0.2 = 5𝑥. Computing
the forward differences Δ𝑘 𝑓 (𝑥0 ) for 𝑘 = 1, 2, 3, we obtain

Δ𝑓 (𝑥0 ) = 𝑓 (𝑥1 ) − 𝑓 (𝑥0 )


= 𝑓 (0.2) − 𝑓 (0.0)
= 1.22140 − 1.00000
= 0.22140,
2
Δ 𝑓 (𝑥0 ) = 𝑓 (𝑥2 ) − 2𝑓 (𝑥1 ) + 𝑓 (𝑥0 )
= 𝑓 (0.4) − 2𝑓 (0.2) + 𝑓 (0.0)
= 1.49182 − 2(1.22140) + 1.00000
= 0.04902,
3
Δ 𝑓 (𝑥0 ) = 𝑓 (𝑥3 ) − 3𝑓 (𝑥2 ) + 3𝑓 (𝑥1 ) − 𝑓 (𝑥0 )
= 𝑓 (0.6) − 3𝑓 (0.4) + 3𝑓 (0.2) − 𝑓 (0.0)
= 1.82212 − 3(1.49182) + 3(1.22140) − 1.00000
= 0.01086,
4
Δ 𝑓 (𝑥0 ) = 𝑓 (𝑥4 ) − 4𝑓 (𝑥3 ) + 6𝑓 (𝑥2 ) − 4𝑓 (𝑥1 ) + 𝑓 (𝑥0 )
= 𝑓 (0.8) − 4𝑓 (0.6) + 6𝑓 (0.4) − 4𝑓 (0.2) + 𝑓 (0.0)
= 2.22554 − 4(1.82212) + 6(1.49182) − 4(1.22140) + 1.00000
= 0.00238.

It follows that
4 ( )
∑ 5𝑥
𝑝4 (𝑥) = 𝑓 [𝑥0 ] + Δ𝑘 𝑓 (𝑥0 )
𝑘
𝑘=1
1
= 𝑓 (𝑥0 ) + 5𝑥Δ𝑓 (𝑥0 ) + 5𝑥(5𝑥 − 1)Δ2 𝑓 (𝑥0 ) +
2
1 1
5𝑥(5𝑥 − 1)(5𝑥 − 2)Δ3 𝑓 (𝑥0 ) + 5𝑥(5𝑥 − 1)(5𝑥 − 2)(5𝑥 − 3)Δ4 𝑓 (𝑥0 )
6 24
0.04902 0.01086
= 1 + (0.22140)5𝑥 + 5𝑥(5𝑥 − 1) + 5𝑥(5𝑥 − 1)(5𝑥 − 2) +
2 6
0.00238
5𝑥(5𝑥 − 1)(5𝑥 − 2)(5𝑥 − 3)
24
= 1 + 1.107𝑥 + 0.61275𝑥(𝑥 − 0.2) + 0.22625𝑥(𝑥 − 0.2)(𝑥 − 0.4) +
0.061979𝑥(𝑥 − 0.2)(𝑥 − 0.4)(𝑥 − 0.6).

Evaluting this polynomial at 𝑥 = 0.05 yields 𝑝3 (0.05) = 1.05126.


(b) Use the Newton backward divided-difference formula to approximate 𝑓 (0.65).

5
Solution Recall the Newton backward-difference formula,
𝑛 ( )

𝑘 −𝑠
𝑝𝑛 (𝑥) = 𝑓 [𝑥𝑛 ] + (−1) ∇𝑘 𝑓 (𝑥𝑛 ).
𝑘
𝑘=1
Since the spacing ℎ is (0.8−0.0)/4 = 0.2, we have 𝑠 = (𝑥−0.8)/0.2 = 5𝑥−4. Computing
the backward differences Δ𝑘 𝑓 (𝑥3 ) for 𝑘 = 1, 2, 3, 4, we obtain
∇𝑓 (𝑥4 ) = 𝑓 (𝑥4 ) − 𝑓 (𝑥3 )
= 𝑓 (0.8) − 𝑓 (0.6)
= 2.22554 − 1.82212
= 0.40342,
2
∇ 𝑓 (𝑥4 ) = 𝑓 (𝑥4 ) − 2𝑓 (𝑥3 ) + 𝑓 (𝑥2 )
= 𝑓 (0.8) − 2𝑓 (0.6) + 𝑓 (0.4)
= 2.22554 − 2(1.82212) + 1.49182
= 0.07312,
3
∇ 𝑓 (𝑥4 ) = 𝑓 (𝑥4 ) − 3𝑓 (𝑥3 ) + 3𝑓 (𝑥2 ) − 𝑓 (𝑥1 )
= 𝑓 (0.8) − 3𝑓 (0.6) + 3𝑓 (0.4) − 𝑓 (0.2)
= 2.22554 − 3(1.82212) + 3(1.49182) − 1.22140
= 0.01324,
4
∇ 𝑓 (𝑥4 ) = 𝑓 (𝑥4 ) − 4𝑓 (𝑥3 ) + 6𝑓 (𝑥2 ) − 4𝑓 (𝑥1 ) + 𝑓 (𝑥0 )
= 𝑓 (0.8) − 4𝑓 (0.6) + 6𝑓 (0.4) − 4𝑓 (0.2) + 𝑓 (0.0)
= 2.22554 − 4(1.82212) + 6(1.49182) − 4(1.22140) + 1.00000
= 0.00238.
It follows that
4 ( )

𝑘 4 − 5𝑥
𝑝4 (𝑥) = 𝑓 [𝑥4 ] + (−1) ∇𝑘 𝑓 (𝑥4 )
𝑘
𝑘=1
1
= 𝑓 (𝑥4 ) − (4 − 5𝑥)∇𝑓 (𝑥4 ) + (4 − 5𝑥)(3 − 5𝑥)∇2 𝑓 (𝑥4 ) −
2
1 1
(4 − 5𝑥)(3 − 5𝑥)(2 − 5𝑥)∇3 𝑓 (𝑥4 ) + (4 − 5𝑥)(3 − 5𝑥)(2 − 5𝑥)(1 − 5𝑥)∇4 𝑓 (𝑥4 )
6 24
0.07312
= 2.22554 − (0.40342)(4 − 5𝑥) + (4 − 5𝑥)(3 − 5𝑥) −
2
0.01324 0.00238
(4 − 5𝑥)(3 − 5𝑥)(2 − 5𝑥) + (4 − 5𝑥)(3 − 5𝑥)(2 − 5𝑥)(1 − 5𝑥)
6 24
= 2.22554 + 2.0171(𝑥 − 0.8) + 0.914(𝑥 − 0.8)(𝑥 − 0.6) +
0.27583(𝑥 − 0.8)(𝑥 − 0.6)(𝑥 − 0.4) + 0.061979(𝑥 − 0.8)(𝑥 − 0.6)(𝑥 − 0.4)(𝑥 − 0.2).

6
Evaluting this polynomial at 𝑥 = 0.65 yields 𝑝4 (0.65) = 1.91555.

11. (a) Show that the Newton forward divided-difference polynomials

𝑃 (𝑥) = 3 − 2(𝑥 + 1) + 0(𝑥 + 1)(𝑥) + (𝑥 + 1)𝑥(𝑥 − 1)

and
𝑄(𝑥) = −1 + 4(𝑥 + 2) − 3(𝑥 + 2)(𝑥 + 1) + (𝑥 + 2)(𝑥 + 1)𝑥
both interpolate the data
𝑥 −2 −1 0 1 2
𝑓 (𝑥) −1 3 1 −1 3
Solution Substituting each of the given 𝑥-values into both 𝑃 (𝑥) and 𝑄(𝑥), we obtain
the corresponding values of 𝑓 (𝑥).
(b) Why does part (a) not violate the uniqueness property of interpolating polynomials?
Solution 𝑃 (𝑥) and 𝑄(𝑥) are the same polynomial, but they are written in the Newton
form using different centers.

19. Given

𝑃𝑛 (𝑥) = 𝑓 [𝑥0 ] + 𝑓 [𝑥0 , 𝑥1 ](𝑥 − 𝑥0 ) + 𝑎2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )


+𝑎3 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) + ⋅ ⋅ ⋅
+𝑎𝑛 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) ⋅ ⋅ ⋅ (𝑥 − 𝑥𝑛−1 ),

use 𝑃𝑛 (𝑥2 ) to show that 𝑎2 = 𝑓 [𝑥0 , 𝑥1 , 𝑥2 ].


Solution We have

𝑃𝑛 (𝑥2 ) = 𝑓 [𝑥0 ] + 𝑓 [𝑥0 , 𝑥1 ](𝑥2 − 𝑥0 ) + 𝑎2 (𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )


+𝑎3 (𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )(𝑥2 − 𝑥2 ) + ⋅ ⋅ ⋅
+𝑎𝑛 (𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )(𝑥2 − 𝑥2 ) ⋅ ⋅ ⋅ (𝑥2 − 𝑥𝑛−1 )
= 𝑓 [𝑥0 ] + 𝑓 [𝑥0 , 𝑥1 ](𝑥2 − 𝑥0 ) + 𝑎2 (𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 ).

It follows from the definition of divided differences that


𝑃𝑛 (𝑥2 ) − 𝑓 [𝑥0 ] − 𝑓 [𝑥0 , 𝑥1 ](𝑥2 − 𝑥0 )
𝑎2 =
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )
𝑓 (𝑥2 ) − 𝑓 (𝑥0 ) − 𝑓 [𝑥0 , 𝑥1 ](𝑥2 − 𝑥0 )
=
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )
𝑓 (𝑥2 ) − 𝑓 (𝑥1 ) + 𝑓 (𝑥1 ) − 𝑓 (𝑥0 ) − 𝑓 [𝑥0 , 𝑥1 ](𝑥2 − 𝑥0 )
=
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )

7
𝑓 (𝑥2 )−𝑓 (𝑥1 ) 𝑓 (𝑥1 )−𝑓 (𝑥0 )−𝑓 [𝑥0 ,𝑥1 ](𝑥2 −𝑥0 )
(𝑥2 −𝑥1 ) + (𝑥2 −𝑥1 )
=
(𝑥2 − 𝑥0 )
𝑓 [𝑥0 ,𝑥1 ](𝑥1 −𝑥0 )−𝑓 [𝑥0 ,𝑥1 ](𝑥2 −𝑥0 )
𝑓 [𝑥1 , 𝑥2 ] + (𝑥2 −𝑥1 )
=
(𝑥2 − 𝑥0 )
𝑓 [𝑥0 ,𝑥1 ](𝑥1 −𝑥2 )
𝑓 [𝑥1 , 𝑥2 ] + (𝑥2 −𝑥1 )
=
(𝑥2 − 𝑥0 )
𝑓 [𝑥1 , 𝑥2 ] − 𝑓 [𝑥0 , 𝑥1 ]
=
(𝑥2 − 𝑥0 )
= 𝑓 [𝑥0 , 𝑥1 , 𝑥2 ].

Potrebbero piacerti anche