Question

Restructure Newton's method (Case Study: Approximating Square Roots) by decomposing it into three cooperating functions.

The newton function can use either the recursive strategy of Project 2 or the iterative strategy of the Approximating Square Roots Case Study. The task of testing for the limit is assigned to a function named limitReached, whereas the task of computing a new approximation is assigned to a function named improveEstimate. Each function expects the relevant arguments and returns an appropriate value.

An example of the program input and output is shown below:

 Enter a positive number or enter/return to quit: 2

The program's estimate is 1.4142135623746899
Python's estimate is      1.4142135623730951
Enter a positive number or enter/return to quitRestructure Newtons method (Case Study: Approximating Square Roots) by decomposing it into three cooperating functions. The
0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the code in python

=========================================================================================

import math
def limitReached(val,last):

    return abs(val - last) < 1e-2

def improvateEstimate(val,n):
    return (val + n / val) * 0.5


def squareroot(n):
    val = n
    while True:
        last = val
        val = improvateEstimate(val,n)
        if limitReached(val,last):
            break
    return val

while True:
    n=(input(' Enter a positive number or enter/return to quit: '))
    if n=='':
        break
    else:
        print('The program\'s estimate is :',squareroot(eval(n)))
        print('Python\'s estimate is      :', math.sqrt(eval(n)))
        print()

========================================================================================

Add a comment
Know the answer?
Add Answer to:
Restructure Newton's method (Case Study: Approximating Square Roots) by decomposing it into three...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a...

    python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...

  • newton.py

    Package Newton’s method for approximating square roots (Case Study: Approximating Square Roots) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The program should also include a main function that allows the user to compute the square roots of inputs from the user and python's estimate of its square roots until the enter/return key is pressed.

  • In Chapter 4, we developed an algorithm for converting from binary to decimal.

    1.In Chapter 4, we developed an algorithm for converting from binary to decimal. You can generalize this algorithm to work for a representation in any base. Instead of using a power of 2, this time you use a power of the base. Also, you use digits greater than 9, such as A . . . F, when they occur.In convert.py, define a function named repToDecimal that expects two arguments, a string, and an integer. The second argument should be the base....

  • I have this case study to solve. i want to ask which type of case study...

    I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...

  • Read through the case study and answer the following questions: Using appropriate concepts and theories from...

    Read through the case study and answer the following questions: Using appropriate concepts and theories from Block 2, Session 2, identify and discuss three main threats and three main opportunities that should be considered by Yum! in expanding its global reach within emerging markets such as China. (25 marks) Twelve marks will be awarded on the basis of the appropriateness of the three main threats and three main opportunities that you have identified (two marks each); there are no standard...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT