Question: Please help with matlab Q1. (10 pts) Write a MATLAB function with inputs - a matrix A of size mn, - a vector x of

Please help with matlab
Q1. (10 pts) Write a MATLAB function with inputs - a matrix A of size mn, - a vector x of size n1, and which outputs the product vector Ax (note that the size of this vector should be m1 ). Your code should check that the sizes of the inputs are right and then do the multiplication using two nested "for" loops. a) Run your code on A=rand(10) and x=rand(10,1) (the command "rand" produces a random matrix). Compare the output of your function to the result when you type Ax into MATLAB (the results should be the same!). b) How many floating point operations (additions and multiplications) does the code use? Find a formula in terms of m and n. (Similar to how we found that a vector-vector multiplication takes 2n operations, where n is the vector length.) Q2. (10 pts) Write a MATLAB function with inputs - a matrix A of size mn, - a matrix B of size np, and which outputs the product matrix AB (note that the size of this matrix should be mp ). Your code should check that the sizes are right and then do the multiplication using three nested "for" loops. a) Run your code on A=rand(10,5) and B=rand(5,7) (the command "rand" produces a random matrix). Compare the output of your function to the result when you type AB into MATLAB (the results should be the same!). b) How many floating point operations (additions and multiplications) does the code use? Find a formula in terms of m,n, and p. Q1. (10 pts) Write a MATLAB function with inputs - a matrix A of size mn, - a vector x of size n1, and which outputs the product vector Ax (note that the size of this vector should be m1 ). Your code should check that the sizes of the inputs are right and then do the multiplication using two nested "for" loops. a) Run your code on A=rand(10) and x=rand(10,1) (the command "rand" produces a random matrix). Compare the output of your function to the result when you type Ax into MATLAB (the results should be the same!). b) How many floating point operations (additions and multiplications) does the code use? Find a formula in terms of m and n. (Similar to how we found that a vector-vector multiplication takes 2n operations, where n is the vector length.) Q2. (10 pts) Write a MATLAB function with inputs - a matrix A of size mn, - a matrix B of size np, and which outputs the product matrix AB (note that the size of this matrix should be mp ). Your code should check that the sizes are right and then do the multiplication using three nested "for" loops. a) Run your code on A=rand(10,5) and B=rand(5,7) (the command "rand" produces a random matrix). Compare the output of your function to the result when you type AB into MATLAB (the results should be the same!). b) How many floating point operations (additions and multiplications) does the code use? Find a formula in terms of m,n, and p
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
