Effacer les filtres
Effacer les filtres

How do I plot a function of one variable easily in matlab?

16 vues (au cours des 30 derniers jours)
Russell
Russell le 19 Fév 2015
Commenté : Star Strider le 19 Fév 2015
This is such a simple thing, I know, I'm just really struggling making it work at all well. I think it's a problem with how I've written the function, something about the element-wise operations. Here's my code:
figure
y = linspace(0,20,0.5);
f = r*y - (r/L_rb)*y.^2 - (p*y.^2)./(q+y.^2);
plot(y,f)
r is 0.65, L_rb is 5.4, p is 1.2 and q is 1. I get a blank plot when I run it.

Réponse acceptée

Star Strider
Star Strider le 19 Fév 2015
This is one problem:
y = linspace(0,20,0.5);
The third argument to linspace is the length of the vector it produces. (The default is 100.)
See if:
y = linspace(0,20);
improves things
  2 commentaires
Russell
Russell le 19 Fév 2015
Yep, thank you!
Star Strider
Star Strider le 19 Fév 2015
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by