write a MATLAB function that takes two matrices A and B as i

write a MATLAB function that takes two matrices A and B as input and returns A * B if A and B are conformable, and returns the empty matrix [] otherwise; You may not use the built in * operator for matrices – only scalars, so you will need to use the definition of matrix multiplication and one loop (column) nested in another loop (row), then either a third nested loop ( k ) or try to use dot() and transposition

Solution

function M=matrixmul(A,B)
x=size(A);
y=size(B);
M=zeros(x(1),y(2));
if(x(2)==y(1))
for i = 1 : x(1)
  
   for j = 1 : y(2)
       theSum = 0;
       for k = 1 : x(2)
           theSum = theSum + A(i, k) * B(k, j);
       end
       M(i, j) = theSum;
   end
end
else
M=[];
end

write a MATLAB function that takes two matrices A and B as input and returns A * B if A and B are conformable, and returns the empty matrix [] otherwise; You ma

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site