Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Programming Choose an epsilon value that determines how close your solution should be to the actual square root value before you decide it is

Python Programming

Choose an epsilon value that determines how close your solution should be to the actual square root value before you decide it is "good enough." Because this assignment asks you to solve for the square root to three decimal places, we can safely set the epsilon value to 0.0001 (four decimal places). This guarantees that our solution will be accurate to the precision we need to display to the screen.

Choose an initial estimate e for the square root of x. An easy and perfectly valid approach is to set the initial estimate e=x. For example, you could set the first estimate for the square root of 4 to be 4.

Evaluate the estimate by dividing the value x by your estimate e, and comparing the result of that division to the current estimate e. If your estimate e were to be exactly equal to the square root, then you would find that x/e=e. In practice, unless you are lucky, there will typically be some difference between these two values (x/e and e) even after many iterations of the algorithm.

Determine if the estimate is "good enough" to stop. A smaller difference between x/e and e reflects a more accurate estimate. If the difference is smaller than your epsilon value, then you've found the answer! If not---if the difference is greater than the epsilon value---then you need to proceed to step 5 below.

Note that you'll want to look at the absolute value of the difference between x/e and e. This is because e may be too large or too small. To test for the absolute value, you could use if/else logic to see which term (x/e or e) is smaller. You could then subtract the smaller value from the larger one. Alternatively, you could use the Python's built-in function abs().

Revise the estimate (if needed based on Step 4) by setting e to the average of the fraction x/e and your old estimate e. Using this new estimate, go back to Step 3.

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

Step: 3

blur-text-image

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

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

What are the forensic values of Jump List?

Answered: 1 week ago

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago