Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have seen that the math library contains a function that computes the square root of numbers. you are to write your own algorithm

You have seen that the math library contains a function that computes the square root of numbers. you are to

You have seen that the math library contains a function that computes the square root of numbers. you are to write your own algorithm for computing square roots. One way to solve this problem is to use a guess-and-check approach. You first guess what the square root might be, and then see how close your guess is. You can use this information to make another guess and continue guessing until you have found the square root (or a close approximation to it). One particularly good way of making guesses is to use Newton's method. Suppose x is the number we want the root of, and guess is the current guessed answer. The guess can be improved by using computing the next guess as: guess + 2 x guess Write a program that implements Newton's method. The program should prompt the user for the value to find the square root of (x) and the number of times to improve the guess. Starting with a guess value of x/2, your program should loop the specified number of times applying Newton's method and report the final value of guess. You should also subtract your estimate from the value of math.sqrt (x) to show how close it is.

Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

python import math def newtonsmethodsqrtx numiterations guess x ... 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

Numerical Methods With Chemical Engineering Applications

Authors: Kevin D. Dorfman, Prodromos Daoutidis

1st Edition

1107135117, 978-1107135116

More Books

Students also viewed these Programming questions

Question

How is safety stock included in a material requirements plan?

Answered: 1 week ago

Question

What are some of the main advantages and limitations of MRP?

Answered: 1 week ago