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?
답변 (1개)
John D'Errico
2017년 10월 14일
편집: John D'Errico
2017년 10월 14일
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? ;-)
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!