How to plot polynomial function correctly?
47 ビュー (過去 30 日間)
古いコメントを表示
Adrian Brand
2020 年 3 月 24 日
コメント済み: María Guadalupe Gama Cruz
2021 年 2 月 24 日
Hello, I'm trying to plot polynomial function but output is always bad. Can you help me find, what I'm missing? Thank you.
This is my code:
d = @(g)1-5*g-2.5*g.^2+6*g.^3+5*g.^4;
e = -2:1/100:2;
plot(e,d(e));
This is what I'm getting:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279158/image.png)
And this is what I want:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279159/image.png)
0 件のコメント
採用された回答
Alex Mcaulley
2020 年 3 月 24 日
Your code is working fine, the difference is just the axis limits. Try this:
d = @(g)1-5*g-2.5*g.^2+6*g.^3+5*g.^4;
e = -2:1/100:2;
plot(e,d(e));
ylim([-2,5])
xlim([-3,6])
0 件のコメント
その他の回答 (1 件)
John D'Errico
2020 年 3 月 24 日
編集済み: John D'Errico
2020 年 3 月 24 日
Hmm. Why does this feel like deja vu? (Answer: I just answered almost the same question for someone else, not 5 minutes ago.)
d = @(g)1-5*g-2.5*g.^2+6*g.^3+5*g.^4;
e = -2:1/100:2;
plot(e,d(e));
grid on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279164/image.jpeg)
It looks fine to me. Whats the problem? That two programs arbitrarily chose a different set of axes to plot the same curve?
axis([-3,4.5,-1.5,4.5])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/279165/image.jpeg)
Same curve. Same plot. Very different conclusions, just by changing the axis scaling.
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!