Question

Please use MATLAB to solve it. Develop, debug, and test your own M-file to multiply two...

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.

Homework Answers

Answer #1

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!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT