Syntax to multiply 10 different 2 by 2 matrices sequentially in matlab

Please I need help with syntax to multiply ten 2 by 2 matrices i.e T = A1*A2*A3*A4*A5*A6*A7*A8*A9*A10 in matlab

2 Comments

"Matrix" multiplication, or "element-by-element" multiplication?
Sir I need syntax for element by element multiplication called from the output of a for loop manipulation. Say T is the output that contains ten different 2 by 2 matrix from the for loop. How do i get their product in this form: T = T1*T2*T3*...* TN TO obtain a SINGLE 2 by 2 answer Thanks

Sign in to comment.

 Accepted Answer

A = cat(3,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10);
s = size(A,3);
out = A(:,:,1);
for jj = 2:s
out = out*A(:,:,jj);
end
or
A = {A1,A2,A3,A4,A5,A6,A7,A8,A9,A10};
out = A{1};
for jj = 2:numel(A)
out = out*A{jj};
end
or for "element by element" multiplication
A = cat(3,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10);
out = prod(A,3);

2 Comments

Thanks for your quick response please what code do I include if this ten 2 by 2 matrices are outputs from a for loop to reference them or call them from the output "A" instead of listing them as A1,A2,A3 etc

Sign in to comment.

More Answers (1)

For element by element multiplication, I believe this should work:
T = A1.*A2.*A3.*A4.*A5.*A6.*A7.*A8.*A9.*A10
If the A's are of class integer, you'll have to watch out if they exceed the max value, intmax('uint8') or intmax('uint16'), or else your product will be clipped. Cast to double before multiplication if that's the case.

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!