Please use MATLAB to solve it.
Develop, debug, and test your own M-file to multiply
two matrices—that is, [X ] = [Y ][Z], where [Y] is m by n
and [Z] is n by p. Employ for...end loops to implement the
multiplication and include error traps to flag bad cases.
Matlab code with explanatory comments is given below:
function [X] = Q_mmult(Y,Z)
%Multiples two matrices Y and Z
[rY,cY]=size(Y);
[rZ,cZ]=size(Z);
if not(cY==rZ)
error("Matrices not compatible for
multiplication");
end
X=zeros(rY,cZ); %initialize matrix X of appropriate size
for row=1:rY
for col=1:cZ
for k=1:cY
X(row,col)=X(row,col)+Y(row,k)*Z(k,col); %matrix multiplication
formulation
end
end
end
end
Sample usage:
Please do rate this answer positively if you found it helpful. Thanks and have a good day!
Get Answers For Free
Most questions answered within 1 hours.