Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a C++ problem. Please give full explanations and code in details. Thanks. The problem of computing the square root of any number is
This is a C++ problem. Please give full explanations and code in details. Thanks.
The problem of computing the square root of any number is a specific case of the more general root-finding problem. Root-finding occurs in many places in computer science, as well as in other science and engineering problems. Recall that the roots (or zeros) of any function are the parametric value(s) for which the function produces a zero result: x:f (x Finding the square root of some number K is equivalent to finding the principal zero of f(x)--1K We could just as easily compute the cube root of K in the same fashion by solving: and so on. Generalizing, we can find the nth root of any value K by solving The Newton-Raphson algorithm is an efficient and ingenious method for finding the principal root of any continuously differentiable function. The method is ascribed to Sir Isaac Newton, although Joseph Raphson was the first to publish it in a more refined form. The method is a generalized version of the Babylonian "guess and check" approach that you explored in a previous lab The method generalizes the Babylonian approach by employing the derivative of the function. Given an old guess, xi, the new ("better") guess, xi-1 1s computed by: f (xi) f'(xi) Note that the Babylonian Algorithm is simply the specific case of Newton-Raphson for f(x)-x-K. For the generalized nth root problem,f (r) is r-K and the derivative,f(x) is Substituting these formulas, the Newton-Raphson update rule for computing the nh root of any value K is m-1 TL Write a program that includes a user-defined function named rootN that will calculate and return the nth root of any value using the Newton-Raphson method described above: double rootN (double, int); The function takes two arguments: a (type double) value > 0 and an integer root> 1. For example, to find the cube root of 42 you'd call the function as rootN (42.0, 3). This function should work exactly as your Babylonian square root, but using the more generalized update rule. Do not use any math library functions in your solution. Hint: it will be very helpful if you also construct a separate function to compute *"] Your main program should take as input positive values for K and n, then call the rootN function to process as long as the user wishes. and display the nh root of the input value. Include a continuation loop that will continue this Examples: enter value and root: 9 2 the root is: 3.00002 continue ? (y): y enter value and root 9 3 the root is: 2.08008 continue ? (y): y enter value and root: 9 4 the root is: 1.73207 continue? (y): nStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started