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?
-
Discuss the following Scripture verse within the context of marketing management. The Scripture verse from the Old Testament: (Joshua 1:9) says, "Have I not commanded you? Be strong and courageous....
-
Consider the following information for HandyCraft Stores for 2017 and 2018: Required a. Compute ROI for both years. b. Break ROI down into profit margin and investment turnover. c. Comment on the...
-
A major purpose of the Information Systems Audit and Control Association's Statements on Information Systems Auditing Standards is to: a. Cover temporary gaps in the General Standards for information...
-
1. Is anything unique about Chriss idea? Explain. 2. What is the first thing he should do to follow up on his idea? Explain. 3. When this is done, what else should Chris do? Outline a general course...
-
AA 2 Question 5 The means that you should not borrow more than 20% of your net income and have more than 10% of your monthly income tied up in debt. A B 20/10 rule budgeting rule Golden Rule 1 Point...
-
A receiver for base band digital data has a threshold set at instead of zero. Rederive (9.8), (9.9), and (9.11) taking this into account. If P(+A) = P(-A) = 1/2, find E b / N 0 in decibels as a...
-
You are considering opening a new plant. The plant will cost $101.86 million up front and will take one year to build. After that, it is expected to produce profits of $31.84 million at the end of...
-
B. INTERNAL CONTROL (9 Marks) Instructions For the weakness in each of the situations given below, describe what could go wrong and make a recommendation to improve internal control. The following...
-
Hydroxylation of A9-THC (a highly lipophilic component of cannabis) generates 11- hydroxy A9-Tetra hydrocannabinol (11-OH-THC), a psychoactive compound. Given the REVISED drug decay model...
-
1. Evaluate the work done by the force F(x,y,)=(x-3y)i+ (6x + 5y)j on a particle moving counterclockwise around the closed triangle path C with vertices (0,0), (5,0) and (0,5)
-
Mae has a debt of $2,400 to pay off with no interest added. If she pays $75 each month, how long will it take her to pay back the loan? The equation can be written as: y = -75x + 2,400 Solve the...
-
Landing guitars ink made 7500 and sales in 2840 and purchases in September and $10,000 and shoes and 30 1132 and purchases in October the majority of shield 80% of meeting cash and remaining 20% I am...
-
1. (2 points) Which figure shows low accuracy and high precision? Which figure shows low precision and high accuracy? Which figure shows high accuracy and high precision? 2. (1 point) List some...
-
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 --[:]...
-
Show that the BFGS formula (B.23) can be written as: \[ \mathbf{C} \leftarrow\left(\mathbf{I}-v \boldsymbol{g} \boldsymbol{\delta}^{\top} ight)^{\top} \mathbf{C}\left(\mathbf{I}-v \boldsymbol{g}...
-
In Exercise 12 above, we train the multi-logit classifier using a weight matrix \(\mathbf{W}\) \(\in \mathbb{R}^{3 \times 7}\) and bias vector \(\boldsymbol{b} \in \mathbb{R}^{3}\). Repeat the...
-
Derive the formula (B.25) for a diagonal Hessian update in a quasi-Newton method for minimization. In other words, given a current minimizer \(\boldsymbol{x}_{t}\) of \(f(\boldsymbol{x})\), a...
Study smarter with the SolutionInn App