Consider the figure below. It plots the function y = log(1 + x)/x computed in tw
ID: 2246481 • Letter: C
Question
Consider the figure below. It plots the function y = log(1 + x)/x computed in two different ways. Mathematically, y is a smooth function of x near x = 0, equaling 1 at 0. But if we compute y using this formula, we get the plots on the left (shown in the ranges x belongsto [-1, 1] on the top left and x belongsto [-10^-15, 10^-15] on the bottom left). This formula is clearly unstable near x = 0. On the other hand, if we use the algorithm d = 1 + x if d = 1 then y = 1 else y = log (d)/(d - 1) end if we get the two plots on the right, which are correct near x = 0. Explain this phenomenon, proving that the second algorithm must compute an accurate answer in floating point arithmetic. Assume that the log function returns an accurate answer for any argument. (This is true of any reasonable implementation of logarithm.) Assume IEEE floating point arithmetic if that makes your argument easier. (Both algorithms can malfunction on a Cray machine.)Explanation / Answer
Explanation: In first case, for x = 0, computed value of y will be log(1+0)/0 which is not defined or not-a-number (NaN) from computational point of view. Clearly, behaviour of function will be unstable for x =0. This is properly visible from the plots in first case.
While for second case, the value of y for d=1 is fixed one through if condition, not the computed one. So, although plotted properly, it does not capture the actual behaviour of function and can not be termed as a true plot to depict the behaviour of the function.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.