Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function to implement this. Correct answer immediate upvote The sqrt) function of a number can be calculated using the following recursive definition, which

Write a function to implement this. Correct answer immediate upvote

image text in transcribed

The sqrt) function of a number can be calculated using the following recursive definition, which is based on Newton's method. We can write a recursive algorithm that finds the square root of a real valued (double or floating point) number to within a given tolerance epsilon (where epsilon might be 0.0001 if you want a result that is correct to 4 decimal places) Suppose x is a nonnegative real number, and a is the approximate square root of x and epsilon is the tolerance. Start with an approximate guess of a x 1. if a2-x| epsilon , then a is the square root of x within the tolerance. (this is your base case) 2. otherwise, replace a with and repeat step 1 Write a function to implement this algorithm to find the square root of a nonnegative real number. This function will take two double numbers as input parameters, and it will return a double result, which should be the square root of the value initially asked for (to within epsilon tolerance). The two parameters are the value x we want to find the square root of, and the value a, which is the current guess/iteration. So for example, if you want to find the square root of 5, you would first call your function with 5, and an initial guess of a-x-5, like this double x-5; double a-x / the initial guess double root; root sqrt (x, a); You can either define epsilon as a const double in your function, like const double epsilon-0.0001; or an even better approach is to have a third default parameter for your sqrt0) function call epsilon that defaults to the usual desired tolerance

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

More Books

Students also viewed these Databases questions

Question

Write formal proposal requests.

Answered: 1 week ago

Question

Write an effective news release.

Answered: 1 week ago

Question

Identify the different types of proposals.

Answered: 1 week ago