Question: 2 . 7 Exercises 8 7 Exercise 2 . 1 9 : Explore round - off errors from a large number of inverse operations Maybe

2.7 Exercises
87
Exercise 2.19: Explore round-off errors from a large number of inverse operations
Maybe you have tried to hit the square root key on a calculator multiple times and then squared the number again an equal number of times. These set of inverse mathematical operations should of course bring you back to the starting value for the computations, but this does not always happen. To avoid tedious pressing of calculator keys, we can let a computer automate the process. Here is an appropriate program:
from math import sqrt
for n in range (1,60) :
r=2.0
for i in range(n):
r=r2
for i in range(n):
r=r****2
print % d times sqrt and ****2:%.16f,%(n,r)
Explain with words what the program does. Then run the program. Round-off errors are here completely destroying the calculations when n is large enough! Investigate the case when we come back to 1 instead of 2 by fixing an n value where this happens and printing out r in both for loops over i. Can you now explain why we come back to 1 and not 2?
Filename: repeated_sqrt.
Exercise 2.20: Explore what zero can be on a computer
Type in the following code and run it:
eps=1.0
while 1.0,1.0+ eps:
print '..........', eps
eps =eps2.0
print 'final eps:', eps
Explain with words what the code is doing, line by line. Then examine the output. How can it be that the "equation" 11+ eps is not true? Or in other words, that a number of approximately size 10-16(the final eps value when the loop terminates) gives the same result as if eps were zero?
Filename: machine_zero.
Remarks The nonzero eps value computed above is called machine epsilon or machine zero and is an important parameter to know, especially when certain math-
 2.7 Exercises 87 Exercise 2.19: Explore round-off errors from a large

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!