Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that if A is an m x n matrix and B is a p x q matrix, then the product C = AB is

Recall that if A is an m x n matrix and B is a p x q matrix, then the product C = AB is defined if and only if n = p, in which case C is an m x q matrix.
Each column of the matrix AB can be computed as the product of A times the corresponding column of B:
For instance, if A is 3 x 4 and B is 4 x 5, the product is given by the matrix
i.e., where and are the jth columns of C and B respectively.
Write a function named columnproduct that takes as input two matrices A and B and a random number k, and as output produces the product, C, by columns of the two matrices and the intermediate value, z, of the output matrix at the end of k iterations (the matrix z is used by MATLAB Grader to determine whether your code is correct).
The function should work for any dimension of A and B and it should perform a check to see if the dimensions match and return an empty product matrix if the dimensions do not match.
Specific instructions for writing the function:
Extract the dimension of A using the command size and store the result in the variables m and n.
Extract the dimension of B using the command size and store the result in the variables p and q
Use an if statement to perform a check on the dimensions to determine whether the multiplication is defined
If the multiplication is defined:
initialize the vector C as a matrix of zeros of the appropriate dimension
use a single for loop to evaluate the product C = AB. The loop counter should be the variable j. Each iteration of the for loop should evaluate the jth column of the matrix C as the product of A times the jth column of the matrix B. Also, inside the for loop, after you compute the jth column of C, insert the following commands:
if isequal(j,k)
z = C;
end
If the multiplication is not defined, display the message 'dimensions do not match' and return an empty C vector and an empty z vector.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

Which VPN solution can be used with computers running Windows XP?

Answered: 1 week ago