how to store equation values in array or matrix
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Samadhan Mahajan
le 18 Août 2019
Commenté : Samadhan Mahajan
le 22 Août 2019
Hi,
for r=0:n;
y=factorial(n)/((factorial(n-r))*factorial(r))*((p)^(n-r))*(q)^(r);
end
How to store values of y in array?
0 commentaires
Réponse acceptée
KALYAN ACHARJYA
le 18 Août 2019
Modifié(e) : KALYAN ACHARJYA
le 18 Août 2019
i=1;
y=zeros(1,n+1);
for r=0:n;
y(i)=factorial(n)/((factorial(n-r))*factorial(r))*((p)^(n-r))*(q)^(r);
i=i+1;
end
Or if you can afford to change the for loop range
y=zeros(1,n+1);
for r=1:n+1 % Note: I have change the i srarting value
y(n)=factorial(n)/((factorial(n-r))*factorial(r))*((p)^(n-r))*(q)^(r);
end
5 commentaires
KALYAN ACHARJYA
le 18 Août 2019
Yes, @Madhan, I didnot think about it, just answer the question how to store the array values, I did small modification on owner code only.
Yes agreed, Without loop is efficient.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!