Effacer les filtres
Effacer les filtres

Plotting functions using loop

2 vues (au cours des 30 derniers jours)
mohammed shapique
mohammed shapique le 10 Sep 2020
lambda=1
gamma1=0.3
n=0:1:15;
for i=1:15
n=0+i;
P1(n)=((lambda.^n)/(lambda+gamma1).^(n+1));
end
After running this program, in the command box i typed plot(P1(:)). The curve starts from 1 and not from zero. please help me to find the mistake in the program.
  1 commentaire
Steven Lord
Steven Lord le 10 Sep 2020
When you call plot with one vector input that input is used as the y data. The corresponding x data is the indices of the elements in the vector and array indices in MATLAB start at 1. See the Description section of the plot function's documentation page for more information.
Asad (Mehrzad) Khoddam has given you a vectorized solution that calls plot with two inputs.

Connectez-vous pour commenter.

Réponse acceptée

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam le 10 Sep 2020
lambda=1;
gamma1=0.3;
n=0:1:15;
P1 = (lambda.^n)./(lambda+gamma1).^(n+1));
plot(n, P1);
  1 commentaire
mohammed shapique
mohammed shapique le 10 Sep 2020
Thank you sir.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by