Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

- Consider the following Matlab function: function [r1 r2] = ratio(x1,x2,n) ri = zeros(n,1,'single'); r2 = r1; for k = 1:n r1(k) x1 (2 k)/x2 (2 k); r2(k) = (x1/2) (2 k); end and run it with the following matlab script function as driver: x1 = single(10); x2 = single(30); 7; [r1 r2] = ratio (x1,x2,n); [r1 r2] Clearly the function computes, in single precision, the ratio n 24 X 1 (1) 2 X 2 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. - Consider the following Matlab function: function [r1 r2] = ratio(x1,x2,n) ri = zeros(n,1,'single'); r2 = r1; for k = 1:n r1(k) x1 (2 k)/x2 (2 k); r2(k) = (x1/2) (2 k); end and run it with the following matlab script function as driver: x1 = single(10); x2 = single(30); 7; [r1 r2] = ratio (x1,x2,n); [r1 r2] Clearly the function computes, in single precision, the ratio n 24 X 1 (1) 2 X 2 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

What is the coefficient for the BANK-Dummy variable?

Answered: 1 week ago