Answered step by step
Verified Expert Solution
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
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started