Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using MATLAB Instructions: For the following exercise, copy and paste into a text document the function M-files and the output obtained by running them. 4.
Using MATLAB
Instructions: For the following exercise, copy and paste into a text document the function M-files and the output obtained by running them.
4. The product y = Ax of an mxn matrix A times a vector x = (21, 12,..., In) can be computed row-wise as y = [A(1,:)*x; A(2,:)*x; ... ;A(m, :)*x]; that is y(1) = A(1,:)*x y (2) = A(2,:)*x y(m) = A(m, :)** Write a function M-file that takes as input a matrix A and a vector x, and as output gives the product y = Ax by row, as defined above (Hint: use a for loop to define each entry of the vector y.) Your M-file should perform a check on the dimensions of the input variables A and x and return a message if the dimensions do not match. Call the file myrowproduct.m. Note that this file will NOT be the same as the myproduct.m example. Test your function on a random 4 x 6 matrix A and a random 6 x 1 vector x. Compare the output with A*x. Repeat with a 5 x 3 matrix and a 3 x 1 vector and with a 5 x 3 matrix and a 1 x 3 vector. Use the command rand to generate the random matrices for testing. Include in your lab report the function M-file and the output obtained by running itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started