Practical 6

Plotting

Plotting polynomials with MATLAB can be done using arrays and function m-files.

> Exercise: A Polynomial Plot Function

> Create a function M-file called plotPoly.m that uses an array of polynomial  coefficients to plot the polynomial over an interval specified by the user.

% Input: coefficient array, endpoints array.

% Output: polynomial graph.

% **create x array using linspace**

% **create y array using polyval**

% **plot the graph using the plot command**

> Test your function for p and q from the previous exercise at the interval [-5, 5].

> Exercise: Fitting a Polynomial Curve

> Check the help files under polynomial functions for an appropriate function that fits a polynomial to a set of given data points.

> Create a script M-file called fitPoly.m with the following two cells

1) Fit the points (1,7), (2,-1) and (3,3).

2) Plot the resulting polynomial with your plotting M-file.