Question: 1. Consider the following Matlab function: function (r1 r2] = ratio(x1,x2,n) r1 = zeros(n,1,'single'); r2 = r1; for k = 1:n r1(k) x1(2 k)/x2* (2

 1. Consider the following Matlab function: function (r1 r2] = ratio(x1,x2,n)r1 = zeros(n,1,'single'); r2 = r1; for k = 1:n r1(k) x1(2

1. Consider the following Matlab function: function (r1 r2] = ratio(x1,x2,n) r1 = zeros(n,1,'single'); r2 = r1; for k = 1:n r1(k) x1(2 k)/x2* (2 k); r2(k) = (x1/x2)^(2 k); end and run it with the following matlab script function as driver: x1 = single(10); x2 = single (30); n = 7; [r1 r2] = ratio(x1,x2,n); [r1 r2] Clearly the function computes, in single precision, the ratio 24 21 02 in two different ways for k=1:7. (a) Describe how a single precision floating point number is stored in IEEE arithmetic as well as what limits are imposed on the accuracy and magnitude of this number. (b) Present the results from running the above driver program. Since (1) is true, one can conclude that the two methods should give identical results. Explain why this is not true as the values of k increase. (c) Which of the two methods is faster and why? (d) If you convert the computation above to double precision then the difference between the two methods in (1) disappears. Does this mean that the two formulas are numerically equivalent (that is, in the presence of floating point arithmetic) when double precision is used? Explain your assertion. 2. Consider the Gaxpy Update y = y + A with A RX, ER" and y ER". (a) Derive two algorithms for its computation. The first should access A by row and the second by column. Present them mathematically and implement them in matlab (or any other language you wish, but you should identify it). (b) Time the execution of the two implementations for n = 1000 (feel free to use other values, eg. n = 10.000) using matlab's tic, toc and explain why the two algorithms differ by almost an order of magnitude. Run your code at least five times in order to get some statistical significance. 1. Consider the following Matlab function: function (r1 r2] = ratio(x1,x2,n) r1 = zeros(n,1,'single'); r2 = r1; for k = 1:n r1(k) x1(2 k)/x2* (2 k); r2(k) = (x1/x2)^(2 k); end and run it with the following matlab script function as driver: x1 = single(10); x2 = single (30); n = 7; [r1 r2] = ratio(x1,x2,n); [r1 r2] Clearly the function computes, in single precision, the ratio 24 21 02 in two different ways for k=1:7. (a) Describe how a single precision floating point number is stored in IEEE arithmetic as well as what limits are imposed on the accuracy and magnitude of this number. (b) Present the results from running the above driver program. Since (1) is true, one can conclude that the two methods should give identical results. Explain why this is not true as the values of k increase. (c) Which of the two methods is faster and why? (d) If you convert the computation above to double precision then the difference between the two methods in (1) disappears. Does this mean that the two formulas are numerically equivalent (that is, in the presence of floating point arithmetic) when double precision is used? Explain your assertion. 2. Consider the Gaxpy Update y = y + A with A RX, ER" and y ER". (a) Derive two algorithms for its computation. The first should access A by row and the second by column. Present them mathematically and implement them in matlab (or any other language you wish, but you should identify it). (b) Time the execution of the two implementations for n = 1000 (feel free to use other values, eg. n = 10.000) using matlab's tic, toc and explain why the two algorithms differ by almost an order of magnitude. Run your code at least five times in order to get some statistical significance

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 Databases Questions!