Why doesn't my code proprely plot the polynomial?

My objective is to plot a polynomial in the intervall -2 to 2 and then fill the area under the curve with red.
f = @(x) (x^.6 - 8*x.^5 - 5*x.^4 + 40*x.^3 + 4*x.^2 - 32*x);
fplot(f,[-2 2],'k','Linewidth',2);
These are the two first lines of the code and for some reason it just plots the equation from 0 to 2 and draws a vertical dotted line at x=0. Why won't it plot for -2 to 0?

Respuestas (1)

John D'Errico
John D'Errico el 14 de Oct. de 2017
Editada: John D'Errico el 14 de Oct. de 2017
You need to look at your typing.
f = @(x) (x^.6 - 8*x.^5 - 5*x.^4 + 40*x.^3 + 4*x.^2 - 32*x);
Are you computing x.^6 there, or are you computing x^0.6? There is a difference. I think you really wanted to type this instead.
f = @(x) (x.^6 - 8*x.^5 - 5*x.^4 + 40*x.^3 + 4*x.^2 - 32*x);
It is a subtle, but important difference. Remember that MATLAB executes what you tell it to do, not what you want it to do. But then, how can I know what you want? ;-)

Categorías

Más información sobre Polynomials en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Oct. de 2017

Comentada:

el 14 de Oct. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by