Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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) = 0 Finding the square root of some number K is equivalent to finding the principal zero o f (x) = x^2 K We could just as easily compute the cube root of K in the same fashion by solving: x^3 N = 0 and so on. Generalizing, we can find the nth root of any value K by solving: 4 x^n K = 0 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" The method generalizes the Babylonian approach by employing the derivative of the function. Given an old guess, xi, the new ("better") guess, xi+1 is computed by:

image text in transcribed

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 x, int n);

The function takes two arguments: a (type double) value > 0 and an integer root > 1. 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 x^n ]

Your main program should take as input positive values for K and n, then call the rootN function to determine and display the n th root of the input value. Include a continuation loop that will continue this process as long as the user wishes.

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): n

Code in C++

D+1 = 0-to Enr n Li Li n nux - L(n = 1), + -1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

=+a. How was the Web site developed?

Answered: 1 week ago