This preview shows page 1. Sign up to view the full content.
Unformatted text preview: 128
Note that the ﬁrst column of the augmented matrix (9) is crafted by raising every element of the
vector x to the fourth power. The second column is built by raising each element of the vector
x to the third power, and so on. The last column of the augmented matrix (9) is a vector of ones
that has the same size as the vector x. Matlab’s elementwise operators make it extremely easy
to build the augmented matrix.
>> M=[x.ˆ4,x.ˆ3,x.ˆ2,x,ones(size(x)),y]
M=
16
8
4
2
1
26
1
1
1
1
1
2
1
1
1
1
1
4
16
8
4
2
1
2
256
64
16
4
1
128
Next, place the augmented matrix in reduced row echelon form. The
Interpolating
Polynomial title page
contents
previous page
next page
back
print doc
close
exit >> R=rref(M)
R=
1
0
0
1
0
0
0
0
0
0 The
0
0
1
0
0 0
0
0
1
0 0
0
0
0
1 1
2
0
1
4 Interpolating
Polynomial Hence, a = 1, b = −2, c = 0, d = 1, and e = −4. Substitute these values in the general form
y = ax 4 + bx 3 + cx 2 + dx + e and the interpolating polynomial is y = 1x 4 − 2x 3 + 0x 2 + 1x − 4,
or p(x) = x 4 − 2x 3 + x − 4. Enter this polynomial at the Matlab prompt as follows:
>> p=[1 2 0 1 4]’
p=
1
2
0
1
4
Again, if the interpolating polynomial does not pass through each of the original data points,
then our answer is wrong. So, let’s plot the data points, then determine whether our solution
passes through each data point.
Recall that the original data are still stored in the vectors x and y. We need only create a set
of data points satisfying our polynomial. The minimum x value in our data set is −2 and the
maximum x value is 4. Let’s plot the polynomial on the interval [−3, 5]. This will insure that
each of our data points is visible in the ﬁnal plot.
You can use column vectors with the plot command as easily as row vectors. The following
commands produce an image similar to that in Figure 5. Because the polynomial passes through
each data point, it is highly likely that we have found the correct interpolating polynomial. title page
contents
previous page
next page
back
print doc
close
exit >> xp=(linspace(3...
View
Full
Document
This document was uploaded on 02/14/2014.
 Summer '12

Click to edit the document details