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

this is the dot product of row i of A with column j of B. A=[1 2 3; 4 5 6; 7 8 9

ID: 3544546 • Letter: T

Question

                    this is the dot product of row i of A with column j of B.                 

                

                    A=[1 2 3; 4 5 6; 7 8 9; 10 11 12]                 

                

                    B=[2 1 6 5 10; 1 7 11 18 3; 20 3 5 9 2] to equal
                

                

                    C=[64 24 43 68 22; 133 57 109 164 67; 202 90 175 260 112; 271 123 241 356 157]                 

                

                    since each element of C is a dot product, you will need three levels of for loops( with three loop control variables):                 

                

                    -an outler loop for each row in C                 

                

                    -an intermediate loop for each column of C                 

                

                    -an intermost loop to perform the dot product of row i of A with column j of B                 

                

                    Write a user defined function called MatrixProduct which multiplies two compatible matrices.                 

                

                    a.) the function whould take two input arguments: A and B                 

                

                    b.)the function have one output argument: C                 

                

                    c.) the function should check to make sure A and B are compatible. if they are not, the function should assign "-1" to the output matrix C                 

                                     d.)use i,j,k and k as the loop control variables for the outer, intermediate and innermost loops

Explanation / Answer

 function [  C ] = my_matrix_mult( A,B ) [m,n]=size(A); [k,l]=size(B); 
if(n~=k)     C=[]; | m==0 | k==0     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