In given example, how can I find multiplication of all c matrices (c1, c2, c3, c4, c5) in a 'for' loop?

3 ビュー (過去 30 日間)
a=[1 2 3 4 5]; c=[]; for i=1:5 b=[1 2; 6 5]*a(i); c=[c b] end

採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 9 月 12 日
Finding c1*c2*c3*c4*c5
a=[1 2 3 4 5];c=1;
for i=1:5
b=[1 2; 6 5]*a(i);
c=c*b;
end
c
c = 2×2
504120 504240 1512720 1512600
  2 件のコメント
MOHD UWAIS
MOHD UWAIS 2022 年 9 月 12 日
why c=1
here c is space matrix of size 2x2.
Dyuman Joshi
Dyuman Joshi 2022 年 9 月 12 日
編集済み: Dyuman Joshi 2022 年 9 月 12 日
I have defined c=1 for the calculation that you desired via a for loop.
So, the required output is y=c1*c2*c3*c4*c5
After c=1;
The loop run as
i=1;
c=c*c1=1*c1=c1;
i=2;
c=c*c2=c1*c2;
i=3;
c=c*c3=c1*c2*c3;
i=4;
c=c*c4=c1*c2*c3*c4;
i=5;
c=c*5=c1*c2*c3*c4*c5;
Which is what is desired.
You can manually verify the result as well
a=[1 2 3 4 5];c=[];
for i=1:5
b=[1 2; 6 5]*a(i);
c=[c b];
end
c1=c(1:2,1:2)
c1 = 2×2
1 2 6 5
c2=c(1:2,3:4)
c2 = 2×2
2 4 12 10
c3=c(1:2,5:6)
c3 = 2×2
3 6 18 15
c4=c(1:2,7:8)
c4 = 2×2
4 8 24 20
c5=c(1:2,9:10)
c5 = 2×2
5 10 30 25
cm=c1*c2*c3*c4*c5
cm = 2×2
504120 504240 1512720 1512600

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by