This preview shows page 1. Sign up to view the full content.
Unformatted text preview: the interpolating polynomial
can do some pretty wild things, including missing most of its data points, if the reader truncates the coeﬃcients of the interpolating polynomial beyond a certain number of signiﬁcant
ﬁgures. One way to avoid this problem is to type
format long
at the Matlab prompt. This will provide about 14 signiﬁcant ﬁgures. This bears both good
news and bad news for the user. The good news is the interpolating polynomial will do
what is expected if the reader uses all signiﬁcant ﬁgures of the coeﬃcients provided by
Matlab. The bad news is that it takes forever to type these in at the Matlab prompt. It is also
extremely diﬃcult to type them correctly. In the past, more often than not, most students
have made typing errors when entering these coeﬃcients at the Matlab prompt.
One workaround is to create a script ﬁle with your Matlab commands. Script ﬁles are
like batch ﬁles. You simply list the commands that you want executed, save the ﬁle with a title page
contents
previous page
next page
back
print doc
close
exit name, then enter the name of the ﬁle at the Matlab prompt. Every command in the ﬁle is
executed in sequence.
For example, open the Matlab editor with the edit command, then enter this sequence
of commands from the narrative.
x=[2 1 1 2 4]’
y=[26 2 4 2 128]’
M=[x.ˆ4,x.ˆ3,x.ˆ2,x,ones(size(x)),y]
R=rref(M)
p=[1 2 0 1 4]’
xp=(linspace(3,5))’;
% or try xp=(3:.1:5)’;
yp=polyval(p,xp);
plot(x,y,’ro’,xp,yp,’’)
Save the ﬁle with the name figure5.m. Return to the Matlab prompt and enter the ﬁlename. The
Interpolating
Polynomial title page
contents >> figure5
This should produce the image shown in Figure 5. previous page If you decide to use a script ﬁle on this ﬁrst exercise, then you will ﬁnd it much easier to
eliminate typing mistakes. Just return to the editor, make your changes, save the ﬁle, then
execute the ﬁlename at the Matlab prompt. This is the way that most Matlab gurus work.
Script ﬁles are indeed a blessing. next page There is a second workaround to...
View Full
Document
 Summer '12

Click to edit the document details