Here is a loop that starts with an initial estimate of the square root of a, x, and improves it until it stops changing: while True: y - (x + a / x) / 2 if abs (y - x) < epsilon: break x - y where epsilon has a value like 0.0000001 that determines how close is close enough.
Here is a loop that starts with an initial estimate of the square root of a, x, and improves it until it stops changing: while True: y - (x + a / x) / 2 if abs (y - x) < epsilon: break x - y where epsilon has a value like 0.0000001 that determines how close is close enough.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
This is for Python
Please see attachment
![Here is a loop that starts with an initial estimate of the square root of a, x, and improves it until it
stops changing:
X.
while True:
y = (x + a / x) / 2
if abs (y - x) < epsilon:
break
x = y
where epsilon has a value like 0.0000001 that determines how close is close enough.
Encapsulate this loop in a function called square_root that takes a as a parameter, chooses a
reasonable value of x, and returns an estimate of the square root of a.
To test the square root algorithm in this chapter, you could compare it with math.sqrt. Write a
function named test_square_root that prints a table like this:
1.0 1.0 1.0 0.0
2.0 1.41421356237 1.41421356237 2.22044604925e-16
3.0 1.73205080757 1.73205080757 0.0
4.0 2.0 2.0 0.0
5.0 2.2360679775 2.2360679775 0.0
6.0 2.44948974278 2.44948974278 0.0
7.0 2.64575131106 2.64575131106 0.0
8.0 2.82842712475 2.82842712475 4.4408920985e-16
9.0 3.0 3.0 0.0
The first column is a number, a; the second column is the square root of a computed with the
[your function]; the third column is the square root computed by math.sqrt; the fourth column
is the absolute value of the difference between the two estimates.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc353cc0f-0c4d-4d5b-a3e6-e746dbb90f94%2F1de8eaa0-94fe-4ac1-b466-87a6cc8f40f1%2Fgs0a3at_processed.png&w=3840&q=75)
Transcribed Image Text:Here is a loop that starts with an initial estimate of the square root of a, x, and improves it until it
stops changing:
X.
while True:
y = (x + a / x) / 2
if abs (y - x) < epsilon:
break
x = y
where epsilon has a value like 0.0000001 that determines how close is close enough.
Encapsulate this loop in a function called square_root that takes a as a parameter, chooses a
reasonable value of x, and returns an estimate of the square root of a.
To test the square root algorithm in this chapter, you could compare it with math.sqrt. Write a
function named test_square_root that prints a table like this:
1.0 1.0 1.0 0.0
2.0 1.41421356237 1.41421356237 2.22044604925e-16
3.0 1.73205080757 1.73205080757 0.0
4.0 2.0 2.0 0.0
5.0 2.2360679775 2.2360679775 0.0
6.0 2.44948974278 2.44948974278 0.0
7.0 2.64575131106 2.64575131106 0.0
8.0 2.82842712475 2.82842712475 4.4408920985e-16
9.0 3.0 3.0 0.0
The first column is a number, a; the second column is the square root of a computed with the
[your function]; the third column is the square root computed by math.sqrt; the fourth column
is the absolute value of the difference between the two estimates.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education