Answered step by step
Verified Expert Solution
Link Copied!

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)

image text in transcribedimage text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago