Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. Compare performances of different implementations of the matrix-vector multiplication. An incomplete Matlab code matvecprod.m is attached. (a) Complete the code for matrix-vector multiplication. (b)
3. Compare performances of different implementations of the matrix-vector multiplication. An incomplete Matlab code matvecprod.m is attached. (a) Complete the code for matrix-vector multiplication. (b) Run the program on your computer and record the time needed for each implementation. Here are two remarks. 1. Different implementations may have very different performances, though mathematically they are equivalent. 2. We should call build-in functions for matrix computations if they are available, because they are optimized for your computer. n=10000; A=rand(n); b=rand(n,1); c=zeros(n,1); %%% The following is the first implementation of c=A*b using ij - loop. tic; for i=1:n for j=1:n % complete the missing line to update c(i) end end disp(['ij loop, time: ' num2str(toc) 1 seconds']); %%% The following is the second implementation of c=A*b using ji-loop. c=zeros(n,1); tic; for j=1:n for i=1:n % complete the missing line to update c(i) end end disp(['ji loop, time: num2str(toc) seconds']); %%% The following is the last implementation of c=A*b by calling the build-in function. tic; C=A*b; disp(['build-in function, time: num2str(toc) seconds']); 1
Step 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