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
and which outputs the product vector Ax note that the size of this vector should be
m times
To get the dimensions of the matrix A you can use
mn sizeA;
similarly to how we got the length of the vector u as
n lengthu;
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 and x randthe 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 nSimilar to how we found that a vectorvector multiplication takes n or n 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
