CODE COPIED BELOW n 1000 u randnn1 v randnn1 x randnn1 T

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?

Solution

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

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 = 1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site