You have seen that the math library contains a function that computes the square root of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
python import math def newtonsmethodsqrtx numiterations guess x ... View the full answer
Related Book For
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis
Posted Date:
Students also viewed these programming questions
-
Review the five steps of the Monroe Motivated Sequence persuasive technique. Tell about a time when you used this technique or when you observed someone else using this technique (other than for our...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
How is it that a state, or any state, such as Oregon, can offer more provisions under FMLA (OFLA) than then the federal rule of FMLA does?
-
1. Compute the inventory turnover, days' sales in inventory, and gross profit percentage for Accel's Companies for 2018. 2. Compute days' sales in receivables during 2018. Round intermediate...
-
What are the recognition criteria for income under the Conceptual Framework? How do these differ from the key stated purpose of IAS 18?
-
When you would use claim and delivery?
-
The Piper Cherokee (a light, single-engine general aviation aircraft) has a wing area of 170 ft 2 and a wing span of 32 ft. Its maximum gross weight is 24501b. The wing uses an NACA 65-415 airfoil,...
-
1. Every judicious organisation, even not-for-profit ones, must be primarily concerned with the health of the entity over the long run; the role of management thus becomes critical in charting the...
-
Gold Enterprises acquired 100 percent of Premium Builders stock on December 31, 20X4. Balance sheet data for Gold and Premium on January 1, 20X5, are as follows: At the date of the business...
-
The income statement, also known as the profit and loss (P&L) statement, provides a snapshot of the financial performance of a company during a specified period of time. It reports a firms gross...
-
Nicks Novelties, Inc., is considering the purchase of new electronic games to place in its amusement houses. The games would cost a total of $304,000, have a fifteen-year useful life, and have a...
-
Suppose Nabisco Corporation just issued a dividend of $1.19 per share yesterday. Subsequent dividends will grow at a constant rate of 06.40% indefinitely. If the required rate of return for this...
-
Balance per bookP 2 , 0 0 0 , 0 0 0 Bank charges 6 , 0 0 0 Outstanding checks 4 7 0 , 0 0 0 Deposit in transit 6 0 0 , 0 0 0 Customer note collected by bank 7 5 0 , 0 0 0 Interest on customer note 3...
-
The following data have been extracted from the books of Alfa Ltd . Year. Sales Rs . Profit Rs 2 0 1 9 . 5 , 0 0 , 0 0 0 . ( Loss ) ( 2 5 , 0 0 0 ) 2 0 2 0 . 7 , 5 0 , 0 0 0 . 1 , 0 0 , 0 0 0 Explain...
-
A company purchased land for $ 1 2 0 , 0 0 0 cash; $ 7 , 0 0 0 was spent to demolish an old building on the land before construction of a new building could start; and $ 1 , 5 0 0 was received for...
-
Calculate for project W and X: (a) The annual Net Profit after Tax (b) The annual Cash Flow after Tax 2. Calculate for project Y and Z: (a) Payback Period (b) Accounting rate of return (ARR) based on...
-
From a medical tourist perspective, compare Shouldice with the traditional hospital in terms of the key factors of competition. Using Table 15-3, why would Shouldice attract patients from outside the...
-
Write a MATLAB program to do LU decomposition for the matrix in Example 2.12. Data from Example 2.12: Use the built-in MATLAB solver to find the solution to 2 4 X1 BAGHA TH 4 1 2 2 -2 -3 X3 1 3 -2...
-
Write the determinant of the following 33 matrix A as a sum of the determinants of 2 2 matrices using co-factor expansion on the third row (i = 3): A = 6 3 5 215 23 2
-
Using the LU decomposition in Problem 2.32, determine the value of x 2 for Ax = b if the forcing function is Data from Problem 2.32: In LU decomposition, determine the missing value of L for 5 --[:]...
-
Which of the following combinations results in a decrease in sample size in a sample for attributes? Risk of Assessing Control Risk Too Low a. Increase b. Decrease c. Increase d. Increase Tolerable...
-
Whatare the nine major steps utilized in a comprehensive approach to information system auditing? Explain why each step is important.
-
Identify four monitoring controls the auditor would expect to find in a welldesigned computer system. Explain the objective of each control identified.
Study smarter with the SolutionInn App