Question: ( a ) Write a loop - based code that computes q 2 , where q is size 1 0 0 1 . To test

(a) Write a loop-based code that computes q2, where q is size 1001. To test
your code and show that it works, use the rand function to create a vector q
with random entries. Store the value of q2 as a variable N2q. Then, apply your
method. At the end of the loop, check your error with the following code:
looperror = abs( norm(q,2)- N2q)
(b) Now write a code for computing q2 that avoids using any loops and instead uses
transposes and a matrix-vector product. Store your value in the variable N2qIP,
and then compute the error
IPerror = abs( norm(q,2)- N2qIP)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!