Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Develop, debug, and test a script in matlab to multiply two matrices (i.e., t

ID: 3283775 • Letter: 1

Question

1. Develop, debug, and test a script in matlab to multiply two matrices (i.e., that is, [X] [Y[Z). The code must perform all the steps of the matrix multiplication yourself do not use matlab matrix multiplication (although you may use the matlab methods to test your answer). Be sure to test if the multiplication is dehned for the given set of matrices and to return an error if the multiplication cannot be performed. Test the program using a variety of matrices 2, Put your code from #1 into a function called "mmult" that performs the matrix multiplication of 2 arbitrary matrices The syntax should be ? mmult(a,b) where a and b are the 2 matrices to be multiplied and c is the result. Be sure to test if the multiplication is defined for the given set of matrices and to return an error if the multiplication cannot be performed.

Explanation / Answer

The code for matriz multiplication:

function [C] =mmult(A,B)

[m,n]=size (A);

[k,l]=size(B);

if(n~=k) | m==0 | k==0

C=[ ];

disp('Error, not able to multiply matrices');

return

end

C=zeros(m,1);

for i=0:m;

for j=0:l;

for p=0:n;

flag=1;

C(i,j)=C(i,j) + A(i,p)*B(p,j);

end

end

end

end