Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Order of time complexity is a very important concept in numerical analysis. It i

ID: 2965668 • Letter: O

Question

Order of time complexity is a very important concept in numerical analysis. It is the limit of time measurement for a certain numerical operation as the input size goes to +?. We have already shown one feature about the order of time complexity in class and we will demonstrate it out with this experiment. Please implement the following steps in MATLAB. (MATLAB commands tic, toc will be used here. )

Construct a matrix A with size of 3000-by-3000 and every entry in this matrix is a random number between 0 and 1. The command to use here is rand. After that, construct another random matrix B but the size of B is 6000-by-6000.

Use MATLAB stopwatch timer tic, toc to measure the time for the matrix multiplication A ? A and assign it to the variable t1. Repeat this step for the matrix B and assign the time to the variable t2.

3. Calculate the ratio t2/t1 and discuss about this result. Does your result match with the theoretical result? If not, any suggestion to improve this little experiment.

Please repeat previous steps for the matrix element-by-element multiplication A. ? A and compare the result with the matrix multiplication.

Explanation / Answer

%Matlab code to do above mentioned tasks.

A = rand(3000,3000);
B = rand(6000,6000);
tic
C=A*A;
t1=toc;

D=B*B;
t2=toc;

E=A.*A;
t3=toc;

F=B.*B;
t4=toc;

t4=t4-t3;
t3=t3-t2;
t2=t2-t1;

%executing above commandswe obtain

for matrix multiplication,

t2/t1 = 6.8439 (will vary from system to system, so you may get different results on your PC)

for matrix element-by-element multiplication,

t2/t1 = 3.7435 (will vary from system to system, so you may get different results on your PC)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote