Each
of the problems below is intended to be solved by generating a script or
m-file. Be sure to have a very clearly written header for each M-file so that
anyone reading your work can decipher the sort of problems you are solving in
each M-file. Also, be sure to label all axes and assign each plot a title.
In
this problem set we are going to examine MATLAB functions that allow us to
work with polynomials. We'll look at two of the most basic of operations. The
first will focus on plotting out a polynomial function both explicitly and
using POLYVAL. And then calculating the roots of this polynomial. The second
involves fitting a polynomial equation to a given set of data.
- Read the HELP
pages on the following functions (either by typing "help" and
then the function name at the MATLAB command prompt, or by clicking
these links): poly,
polyval,
polyfit,
roots.
- Generate an
array
**X**that goes from -4 to 4 in steps of 0.1. - Using
**X**evaluate the following equation:
=
**P****X**^{3}-**2X**^{2}-**4.25X**+**7.5**
and plot**P**as a function of**X**. Here, use SUBPLOT so that this plot is on the top half of the plot page. - Generate an
array
**C**that contains the coefficients of this polynomial equation and evaluate the polynomial using POLYVAL. Remember that polynomial coefficients need to be arranged in descending order. - Plot the
output of POLYVAL as a function of
**X**. Here, use SUBPLOT so that this plot is on the bottom half of the plot page. - Use the
coefficient array
**C**and the ROOTS function to find the roots of the polynomial equation. - On the lower graph place a
symbol (e.g. the letter
**R**or the symbol**X**) at the location of each of these roots. There are many ways to place this symbol from using the TEXT command to explicitly plotting a single point. Take your pick and use whatever symbol you'd like but make sure the root locations are clearly marked.
For the next set of problems we're going to use POLYVAL and POLYFIT in an attempt to recreate a particular data set. We'll start out with a low order polynomial and work our way up until we establish a good reproduction of our original data.**Turn in a single M-file and two plot pages (w/ four graphs on each page)**. Click here to see what your resulting plots should look like. - Generate an
array (
**X**) that goes from -2 to 2 in steps of 0.1. - Plot
**X**as a function of sin(**X**) in one panel of a four panel plot page. - Use POLYFIT to
calculate the coefficients of a polynomial that will describe your data
in
**X**. Start with a second order polynomial. - Use POLYVAL to
evaluate the polynomial using array
**X**. - On the same
graph that you plotted
**X**as a function of sin(**X**) now plot**X**as a function of the array generated when you used POLYVAL. How do they compare? Can this second order polynomial recreate a close approximation to your data? - Now let's do
some experimenting. We're going to repeat the last four steps seven(7)
more times. Each time you should plot to a different panel on a 4 panel
plot page. Each time plotting
**both**sin(**X**) and it's polynomial equivalent. So by the end of this you will generate**two separate plot sheets with four graphs on each sheet**. Be sure to appropriately label each graph as to the order of the polynomial being evaluated.
To continue on to the next
core lesson, click here. |