# Hi. I am trying to create a loop to multiply two matricies 40 times such that B*C=D1 and C*D1=D2 and B*D2=D3 and so on . I am very much new to matlab. Can anyone help me on this ?

1 ビュー (過去 30 日間)
mk_ballav 2014 年 10 月 31 日
Commented: mk_ballav 2014 年 11 月 1 日
I am trying to create a loop to multiply two matricies 40 times such that B*C=D1 and C*D1=D2 and B*D2=D3 and so on . I am very much new to matlab. Can anyone help me on this ?

#### 3 件のコメント

Image Analyst 2014 年 10 月 31 日
What's the pattern? I know the product matrix is the right matrix the next time, but what about the left matrix? Does it alternate B, C, B, C, B, C, etc.?
the cyclist 2014 年 11 月 1 日
Also, do you need to keep all the intermediate products, or just the final result?
mk_ballav 2014 年 11 月 1 日
The pattern is after you multiply by product of B*D by C then again have to multiply the product of C*(B*D) by B and simultaneously multiply thereafter products by C and B. I want all the intermediate steps as well.

サインイン to comment.

### 採用された回答

Image Analyst 2014 年 11 月 1 日
Try this:
clc;
b = randi(9, 2, 2)
c = randi(9, 2, 2)
D{1} = b * c;
for k = 2 : 5 % End wherever you want
theRemainder = rem(k, 2);
% Alternate multiplying by b or c
if theRemainder == 0
D{k} = c * D{k-1};
else
D{k} = b * D{k-1};
end
end
celldisp(D);

#### 1 件のコメント

mk_ballav 2014 年 11 月 1 日
Thanx alot

サインイン to comment.