Matlab Question 1. Write Matlab functions that implement a matrix vector product
ID: 643277 • Letter: M
Question
Matlab Question
1. Write Matlab functions that implement a matrix vector product b=Ax using each of the ways discussed in class. You can assume A is a n x n matrix b = MatVecProd_a(A,x)Using a pair of nested loops that access the matrix entries in column major order b = MatVecProd_b(A,x)Using a pair of nested loops that access the matrix entries in row major order b = MatVecProd_c(A,x)Using a single loop which access the matrix entries a column vector at a time b = MatVecProd_d(A,x)Using a single loop which access the matrix entries a row vector at a time Compare the time taken by these implementations against the size of the matrix n for each of these implementations by reporting the average over 10 runs. Plot your results for each of the methods for n=128, 256, 512,1024, 2048,4096. (You need not do the 4096 case, if your computer is too slow on the 2048 one). Make the axes log-log. Also use both lines and points for the plot. Finally you can include a legend, label the axes, and give a title. Explain your results.Explanation / Answer
To run the examples in this section, create a nonscalar structure array with arrays of different sizes in field f1.
Count the number of elements in each f1 field.
The syntax @(x) creates an anonymous function. This code returns
Compute the size of each array in the f1 fields.
This code returns
Compute the mean of each column in the f1 fields of s. Because the output is nonscalar, set UniformOutput to false.
This code returns
Create additional nonscalar structures t and u, and test for equality between the arrays in fields f1 across structures s, t, and u.
This code returns