Section 9.3 Plotting Polynomials
We plot a polynomial just like platting any other function: we evaluate the function at a collection of x-values and then use the plot
command. Let’s return to our previous example:
\begin{equation*}
f(x) = x^5 - 12.1x^4 + 40.59x^3 - 17.01x^2 - 71.95x + 35.88
\end{equation*}
Here is how we plot this function from x = -1.5 to x = 6.7:
f = [1, -12.1, 40.59, -17.01, -71.95, 35.88];
x = -1.5:0.1:6.7;
y = polyval(f,x);
plot(x,y, 'linewidth', 2)
xlabel('x');
ylabel('y = f(x)');
text(-1,120,'f(x) = x^5 - 12.1x^4 + 40.59x^3 - 17.01x^2 - 71.95x + 35.88');
Activity 9.3.
Plot the polynomials
\begin{equation*}
p(x) = 2x^3 - 3x^2 + x + 5
\end{equation*}
\begin{equation*}
q(x) = 3x^4 + x^2 + 2x - 4
\end{equation*}
for \(x\) between -2 and 2. Restrict your y-axis to values between -10 and 10.
Please put your MATLAB code into the textbox.