4 3 title page 2 contents 1 0 previous page 1 next

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: you want to plot your data as discrete points. For example, the command >> plot(x,y,’ro’) The Interpolating Polynomial % or try plot(x,y,’g*’) will produce an image similar to that shown in Figure 2. 4 3 title page 2 contents 1 0 previous page −1 next page −2 −1 0 1 2 3 4 5 Figure 2 Using markers to display discrete data points. Plotting Polynomials in Matlab If Matlab’s plot command connects consecutive points with line segments, it seems at first hopeless that one can plot smooth, continuous curves. However, one can provide a fair approx- back print doc close exit imation of the graph of a curve by sampling the curve at a lot of points. If enough points are used, the curve drawn with the plot command will take on a smooth appearance. To produce the smooth shape of a polynomial in Matlab, you first have to generate a sufficient number of data points that satisfy the equation of the polynomial. The following commands produce the graph of the polynomial p(x) = x 3 − 6x 2 + 3x + 10 over the interval [−2, 6], as shown in Figure 3. >> >> >> >> p=[1 -6 3 10]; x=linspace(-2,6); y=polyval(p,x); plot(x,y) The Interpolating Polynomial %You need a lot of points to draw a smooth curve. Matlab’s linspace command is an easy way to generate a vector of equally spaced points. By default, the command linspace(a,b) generates 100 equally spaced points, starting at a and ending at b. You can generate more points with the syntax is linspace(a,b,N). For example, the command linspace(0,1,1000) generates 1000 equally spaced points, starting at 0 and ending at 1000. title page contents previous page The Interpolating Polynomial Given a set of data points, scientists and mathematicians often need to find a polynomial of specified degree whose graph passes through each of the given data points. Such a polynomial is called an interpolating polynomial. 3 In this exercise, we will find a third degree polynomial that passes through the points (−3, 0), (−2, −3), (0, 3), and (2, −15). A third degree polynomial has th...
View Full Document

This document was uploaded on 02/14/2014.

Ask a homework question - tutors are online