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 view (last 30 days)
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 Comments
mk_ballav
mk_ballav on 1 Nov 2014
Edited: mk_ballav on 1 Nov 2014
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.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Nov 2014
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);

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!