subject

Given a double variable named x that has been declared and given a value , let's use a binary search technique to assign an estimate of its square root to another double variable , root that has also been declared . let's assume that x's value is greater than 1.0 -- that will simplify things a bit . here's the general idea: since x> 1, we know its square root must be between 1 and x itself. so declare two other variables of type double (a and b say) and initialize them to 1 and x respectively. so we know the square root must be between a and b. our strategy is to change a and b and make them closer and closer to each other but alway make sure that the root we're looking for is between them. (such a condition that must always hold is called an invariant.)to do this we will have a loop that at each step finds the midpoint of a and b. it then squares this midpoint value and if the square of the midpoint is less than x we know that the root of x must be bigger than this midpoint: so we assign the midpoint to a (making a bigger and shrinking our a and b interval by and we still can be sure that the root is between a and b. of course if the midpoint's square is greater than x we do the opposite: we assign b the value of midpoint. but when to stop the loop? in this exercise, just stop when the interval between a and b is less than 0.1 and assign root the midpoint of a and b then. we call this a binary search also because at each stage we cut the interval under consideration in half. efficient as this method is, old isaac newton discovered an algorithm that is even more efficient and that's what the library function sqrt uses

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 00:50
Is one of the most injurious events that can happen to a person in a crash.
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
What are two of the most common reasons that peolpe who need mental health care do not access it?
Answers: 1
question
Computers and Technology, 22.06.2019 12:10
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 the square root should be passed as a second argument to the function.) 3. elena complains that the recursive newton function in project 2 includes an extra argument for the estimate. the function’s users should not have to provide this value, which is always the same, when they call this function. modify the definition of the function so that it uses a keyword parameter with the appropriate default value for this argument, and call the function without a second argument to demonstrate that it solves this problem. 4. restructure newton’s method (case study 3.6) by decomposing it into three cooperating functions. the newton function can use either the recursive strategy of project 1 or the iterative strategy of case study 3.6. 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. 5. a list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. define a predicate issorted that expects a list as an argument and returns true if the list is sorted, or returns false otherwise. (hint: for a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return false if the first item in a pair is greater.)
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
What is a scenario where records stored in a computer frequently need to be checked
Answers: 2
You know the right answer?
Given a double variable named x that has been declared and given a value , let's use a binary search...
Questions
question
Mathematics, 23.09.2021 01:00
question
Mathematics, 23.09.2021 01:00
question
Mathematics, 23.09.2021 01:00
question
Business, 23.09.2021 01:00
Questions on the website: 13722360