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
  • Recall that if A is an m times n matrix and B is a p × q matrix

    Recall that if A is an m times 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.  a. Write a function M-file that takes as input two matrices A and B, and as output produces the product by rows of the two matrices. For instance, if A is 3 times 4 and B is...

  • In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename...

    In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename myrowproduct (A,x) Undefined function or variable 'Filename' Did you mean: mfilename : myrowproduct (A, x) Undefined function or variable 'myrowproduct' function y = myrowproduct(A,x); function y my rowp roduct (A, x); Error: Function definition not supported in this context. Create functions in code file. (, 2,,)T 4. The product y Ax of an m x n matrix A times a vector x= can...

  • 1 For n × p and p × m matrices, A and B write a pseudocode to compute the matrix product C AB and perform flop count. dik0kj に! 1 For n × p and p × m matrices, A and B write a pseudocode to com...

    1 For n × p and p × m matrices, A and B write a pseudocode to compute the matrix product C AB and perform flop count. dik0kj に! 1 For n × p and p × m matrices, A and B write a pseudocode to compute the matrix product C AB and perform flop count. dik0kj に!

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

  • 2. Partitioned matrices A matrix A is a (2 x 2) block matrix if it is...

    2. Partitioned matrices A matrix A is a (2 x 2) block matrix if it is represented in the form [ A 1 A2 1 A = | A3 A4 where each of the A; are matrices. Note that the matrix A need not be a square matrix; for instance, A might be (7 x 12) with Aj being (3 x 5), A2 being (3 x 7), A3 being (4 x 5), and A4 being (4 x 7). We can...

  • matlab Problem 6: The Matlab command 'randn(m,n) produces an m x n matrix of random numbers...

    matlab Problem 6: The Matlab command 'randn(m,n) produces an m x n matrix of random numbers that are a realization of a white random process with some probability density function. Moreover, the Matlab command 'rand(m,n)' produces an mxn matrix of random numbers between 0 and 1 that are a realization of a white random process with some probability density function. a) Use Matlab to do the following steps: 1) Let u-randn (10000,1); and plot u. 2) Use the command 'mean(u)'...

  • Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elemen...

    Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...

  • please help me answer this question Lecky Nunber Memnon Cless M 2. Which matrix is not...

    please help me answer this question Lecky Nunber Memnon Cless M 2. Which matrix is not an elementary matrix? 100 100 100 1 1 10 (D). (C). (B). 01 4 001 (A). 0 1 0 00 1 0 1 1 001 3. Which matrix is invertible? 2 3 100 -7 0 3 [1 2 3 (D). 1 2 3 6 4 (C). 0 0 3 3 01 (A). 3 5 9 6 8 18 (B). 004 2 04 4-5a, a-5a...

  • Let A be an m x n matrix and let B be an n x p...

    Let A be an m x n matrix and let B be an n x p matrix. (a) Prove that Col(AB) SColA) (b) Use part (a) to prove that the rank of AB is at most the rank of A (c) Use transpose matrices to prove that the rank of AB is also at most the rank of B.

  • In this exercise, you will work with a QR factorization of an mxn matrix. We will proceed in the ...

    In this exercise, you will work with a QR factorization of an mxn matrix. We will proceed in the way that is chosen by MATLAB, which is different from the textbook presentation. An mxn matrix A can be presented as a product of a unitary (or orthogonal) mxm matrix Q and an upper-triangular m × n matrix R, that is, A = Q * R . Theory: a square mxm matrix Q is called unitary (or orthogona) if -,or equivalently,...

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