{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

context-poly-s

# Anything appearing after the sign is ignored by

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: >> p=[1 0 2 -8]; >> x=[-2 -1 0 1 2]; >> y=polyval(p,x) y= -20 -11 -8 Polynomial % or try x=-2:2; -5 4 The % is Matlab’s comment delimiter. Anything appearing after the % sign is ignored by Matlab when executing a command. In this case, we provide this comment as an alternative command. You should try the commented command in place of the original and see what happens. Plotting in Matlab Plotting is done with Matlab’s plot command. Enter the following command at the Matlab prompt and read the resulting help ﬁle. >> help plot The help ﬁle is rather extensive so we will not reproduce it here. For purposes of this activity, if x and y are vectors of equal length, then the command plot(x,y) plots the elements of vector 2 Interpolating You will only evaluate a polynomial at each point of a vector in this exercise. title page contents previous page next page back print doc close exit y versus those of vector x. The following commands should produce a graph similar to that shown in Figure 1. The Interpolating >> x=[-1 0 2 3 5]; >> y=[2 -2 3 0 4]; >> plot(x,y) Polynomial 4 3 2 title page 1 0 contents −1 previous page −2 −1 0 1 2 3 4 5 Figure 1 The data points are connected by line segements. The idea behind Matlab’s plotting routine is simple. When you execute the command plot(x,y), Matlab ﬁrst plots all possible points (x, y), taking an x -coordinate from the vector x and a y coordinate from the vector y. In this case, Matlab plots the points (−1, 2), (0, −2), (2, 3), (3, 0), and (5, 4). By default, Matlab connects consecutive data points with line segments. Of course, Matlab’s plot command oﬀers a number of alternatives to override this default style. You might want to next page back print doc close exit type help plot again, only this time pay particular attention to the wide variety of linestyles, markers, and color combinations that are available for your plot. There are a number of predeﬁned markers that you can use for your data points in a Matlab plot. Markers are especially valuable when you...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online