Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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-
image text in transcribed

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students explore these related Databases questions