Question: Write a MATLAB function with inputs a matrix A of size m times n , a vector x of size n times 1

Write a MATLAB function with inputs
a matrix A of size m \times n,
a vector x of size n \times 1,
and which outputs the product vector Ax (note that the size of this vector should be
m \times 1).
To get the dimensions of the matrix A, you can use
[m,n]= size(A);
similarly to how we got the length of the vector u as
n = length(u);
Here the semicolon supresses output.
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(9) and x = rand(9,1)(the command rand produces
a random matrix). Compare the output of your function to the result when you
type A x 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 vectorvector multiplication takes 2n (or 2n1, depending on how you count) operations,
where n is the vector length.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!