how to store equation values in array or matrix
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
KALYAN ACHARJYA
2019-8-18
编辑:KALYAN ACHARJYA
2019-8-18
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 个评论
KALYAN ACHARJYA
2019-8-18
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!