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 ?

2 vues (au cours des 30 derniers jours)
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 commentaires
the cyclist
the cyclist le 1 Nov 2014
Also, do you need to keep all the intermediate products, or just the final result?
mk_ballav
mk_ballav le 1 Nov 2014
Modifié(e) : mk_ballav le 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.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 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);

Plus de réponses (0)

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!

Translated by