Question

MATLAB HELP!!! Recall that if A is an m × n matrix and B is a p × q matrix, then the product C = AB is defined if and only if n = p, in which case C is an m × q matrix.

5. Recall that if A is an mx n matrix and B is a px q matrix, then the product C-AB is defined if and only if n = p, in which

0 0
Add a comment Improve this question Transcribed image text
Answer #1


%%Matlab code for row product and column product clear all close all Rnadom matrix A(4X3) and B(3X6) and their product A-randfprintf( Matrix product using function rowproduct\n) disp (rowproduct(A, B)) fprintf( Matrix product using matrix multiplic1.33241071963862 1. 13727405296105 1.81266282325218 Columns 4 through 6 1. 05603130257273 0.646900764769298 1.0216568678775 00.648520298409864 1.05981624033438 1.38143507866166 0.60660413566284 1. 18592768274163 1.22803803148928 0.704904710778998 1.20.353072108487477 0.431430581877311 1.02218005330407 1. 24158957480378 Matrix product using function rowproduct Error using m

%%Matlab code for row product and column product
clear all
close all
%Rnadom matrix A(4X3) and B(3X6) and their product
A=rand(4,3);
B=rand(3,6);

fprintf('Matrix product using function columnproduct\n')
disp(columnproduct(A,B))
fprintf('Matrix product using matrix multiplication\n')
disp(A*B)

%Rnadom matrix A(5X5) and B(5X2) and their product
A=rand(5,5);
B=rand(5,2);

fprintf('Matrix product using function columnproduct\n')
disp(columnproduct(A,B))
fprintf('Matrix product using matrix multiplication\n')
disp(A*B)

%Rnadom matrix A(5X5) and B(2X5) and their product
A=rand(5,5);
B=rand(2,5);

%fprintf('Matrix product using function columnproduct\n')
%disp(columnproduct(A,B))
%fprintf('Matrix product using matrix multiplication\n')
%disp(A*B)


%Rnadom matrix A(4X3) and B(3X6) and their product
A=rand(4,3);
B=rand(3,6);

fprintf('Matrix product using function rowproduct\n')
disp(rowproduct(A,B))
fprintf('Matrix product using matrix multiplication\n')
disp(A*B)

%Rnadom matrix A(5X5) and B(5X2) and their product
A=rand(5,5);
B=rand(5,2);

fprintf('Matrix product using function rowproduct\n')
disp(rowproduct(A,B))
fprintf('Matrix product using matrix multiplication\n')
disp(A*B)

%Rnadom matrix A(5X5) and B(2X5) and their product
A=rand(5,5);
B=rand(2,5);

fprintf('Matrix product using function rowproduct\n')
disp(rowproduct(A,B))
fprintf('Matrix product using matrix multiplication\n')
disp(A*B)


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%Function for Columnproduct
function C= columnproduct(A,B)

    sz1=size(B);
    sz2=size(A);
    if sz1(1)~=sz2(2)
        msg = 'Matrix dimension mismatched';
        error(msg)
    else
        for i=1:sz1(2)
            C(:,i)=A*B(:,i);
        end
    end
  
end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Function for rowproduct
function C= rowproduct(A,B)
    sz1=size(A);
    sz2=size(B);
  
    if sz1(2)~=sz2(1)
        msg = 'Matrix dimension mismatched';
        error(msg)
    else
        for i=1:sz1(1)
            C(i,:)=A(i,:)*B;
        end
    end
  
end


    %%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
MATLAB HELP!!! Recall that if A is an m × n matrix and B is a p × q matrix, then the product C = AB is defined if and on...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT