How to plot polynomial function correctly?
Mostra commenti meno recenti
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:

And this is what I want:

Risposta accettata
Più risposte (1)
John D'Errico
il 24 Mar 2020
Modificato: John D'Errico
il 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;
plot(e,d(e));
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?
axis([-3,4.5,-1.5,4.5])

Same curve. Same plot. Very different conclusions, just by changing the axis scaling.
2 Commenti
Adrian Brand
il 24 Mar 2020
María Guadalupe Gama Cruz
il 24 Feb 2021
how do you plot the x axis?
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!