The bad news is that it takes forever to type these

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the interpolating polynomial can do some pretty wild things, including missing most of its data points, if the reader truncates the coefficients of the interpolating polynomial beyond a certain number of significant figures. One way to avoid this problem is to type format long at the Matlab prompt. This will provide about 14 significant figures. 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 significant figures of the coefficients provided by Matlab. The bad news is that it takes forever to type these in at the Matlab prompt. It is also extremely difficult to type them correctly. In the past, more often than not, most students have made typing errors when entering these coefficients at the Matlab prompt. One workaround is to create a script file with your Matlab commands. Script files are like batch files. You simply list the commands that you want executed, save the file with a title page contents previous page next page back print doc close exit name, then enter the name of the file at the Matlab prompt. Every command in the file 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 file with the name figure5.m. Return to the Matlab prompt and enter the filename. 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 file on this first exercise, then you will find it much easier to eliminate typing mistakes. Just return to the editor, make your changes, save the file, then execute the filename at the Matlab prompt. This is the way that most Matlab gurus work. Script files are indeed a blessing. next page There is a second workaround to...
View Full Document

This document was uploaded on 02/14/2014.

Ask a homework question - tutors are online