Answered step by step
Verified Expert Solution
Question
1 Approved Answer
6. We promised to return to the distinction between catastrophic and be- nign cancellation. Take Ye and ye to be two floats, which for ease
6. We promised to return to the distinction between catastrophic and be- nign cancellation. Take Ye and ye to be two floats, which for ease of ex- position we will take as having round values: Ie = 1234567891234567.0 and xe = 1234567891234566.0. Now, if we try to evaluate xa y we will experience catastrophic cancellation: each of the squaring opera- tions leads to a rounding error and then the subtraction exacerbates that dramatically. Write a Python code that does the following: (a) Carries out the calculation 1234567891234567212345678912345662 using integers, i.e., exactly. (b) Carries out the subtraction 1234567891234567.021234567891234566.02 using floats, i.e., exhibiting catastrophic cancellation. (c) Now, we will employ a trick: x2 - y2 can be re-expressed as (x - y) (x + y). Try using this trick for the floats and see what happens. Does your answer match the integer answer or the catastrophic-cancellation answer? Why? (N.B.: In the case of the quadratic equation we completely eliminated the need for any subtractions, whereas here we are still left with a subtraction, even in the best-case scenario)
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