Clear Filters
Clear Filters

How to plot polynomial function correctly?

46 views (last 30 days)
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;
This is what I'm getting:
And this is what I want:

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 24 Mar 2020
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;

More Answers (1)

John D'Errico
John D'Errico on 24 Mar 2020
Edited: John D'Errico on 24 Mar 2020
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;
grid on
It looks fine to me. Whats the problem? That two programs arbitrarily chose a different set of axes to plot the same curve?
Same curve. Same plot. Very different conclusions, just by changing the axis scaling.


Find more on 2-D and 3-D Plots in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!