How do I program a function that takes two matrices A and B as input and outputs the product matrix A*B? Using MATLAB, with loops and conditionals.
My attempt:
function prodAB=MultiplicoMatrices(A,B)
prod=0;
prodAB=[];
for i=1:length(A)
for j=1:length(B)
prod=prod+A(i,j)*B(j,i);
end
prodAB(i,j)=prod;
prod=0;
end
A =
1 2
3 4
B=[5 6 ; 7 8]
B =
5 6
7 8
>> prodAB=MultiplicoMatrices([1 2; 3 4],[5 6; 7 8])
prodAB =
0 19
0 50