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

CODE COPIED BELOW: n = 1000; u = randn(n,1); v = randn(n,1); x = randn(n,1); The

ID: 3923857 • Letter: C

Question

CODE COPIED BELOW:

n = 1000;
u = randn(n,1); v = randn(n,1); x = randn(n,1);

The following MATLAB code generates three random vectors u, v, x of dimension n = 1000, and calculates the CPU time required to evaluate y = (I + uv^T)x using two equivalent expressions. n = 1000; u = randn(n, 1); v = randn(n, 1); x = randn(n, 1); t1 = cputime; y = (eye(n) + u*v') * x; t1 = cputime - t1 t2 = cputime; y = x + (v'*x) * u; t2 = cputime - t2 Run this code, and compare t_1 and t_2. Repeat for n = 2000. Are your observations consistent with what you expect based on a flop count?

Explanation / Answer

If you run the above code for n=1000, you will get values of t1 and t2 as

t1 =  0.073297

t2 = 2.8400e-04

If you change the value of n to 2000 then you will get values of t1 and t2 as

t1 =  0.24050

t2 = 2.5600e-04

Here t1 value is increasing and t2 value is decreasing so the data is not consistent

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