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

MATLAB help needed Question 48 is the problem Write your own code to perform mat

ID: 3820808 • Letter: M

Question

MATLAB help needed

Question 48 is the problem

Write your own code to perform matrix multiplication. Do not use any vectorizing -- use nested for loops. Details are provided in the problem statement in the text.

function [C]=mymatmult(A,B)
% mymatmult - multiplies two matrices, with looping

Play List: CD 2 Track 20 CD 3 Track 11 CD 3 Track 8 CD 2 Track 1 CD 1 Track 7 CD 3 Track 8 CD 1 Track 3 CD 1 Track 15 CD 3 Track 12 CD 1 Track 6 Sorry, your favorite track was not played. 48. Write your own code to perform matrix multiplication. Recall that to multiply two matrices, the inner dimensions must be the same [Alm, x m X p Every element in the resulting matrix c is obtained by: So, three nested loops are required.

Explanation / Answer

%This script demonstrates matrix multiplication

A=[3 8 0; 1 2 5];

B=[1 3 2 4; 4 5 1 2; 0 2 3 4];

[m n]=size(A);

[nb p]=size(B);

If n~=nb

        disp(‘Cannot perform this matrix multiplication’)

else

         C=zeros(m,p);

         for i=l:m

            for j=l:p

               mysum=0;

                  for k=l:n

                         mysum=mysum + A(i.k) * B(k,j);

                  end

                  C(i , j)= mysum;

              end

            end

          C

end