Approximate a root of function surfaceAreaPrime given its first derivative SurfaceAreaDoublePrime, an initial guess (xGuess) and an error limit.
What will be an ideal response?
```
double newton (double xGuess, double okError, int& converges)
{
double xN, xNplus1, absDiff;
int iter = 0;
xN = xGuess;
do {
++iter;
xNplus1 = xN -
surfaceAreaPrime(xN) / surfaceAreaDoublePrime(xN);
absDiff = fabs(xN-xNplus1);
xN = xNplus1;
} while (absDiff >= okError && iter < MAX_ITER);
if (absDiff < okError) {
converges = 1;
return xN;
} else {
cout << endl << "Newton's method did not converge to a "
<< "minimum surface area in " << MAX_ITER << endl
<< "iterations using an initial guess of " << xGuess
<< " centimeters." << endl;
converges = 0;
return xGuess;
}
}
double surfaceArea (double r)
{
return (2 * M_PI * r * r + 4000 / r);
}
double surfaceAreaPrime (double r)
{
return (4 * M_PI * r - 4000 / (r * r));
}
double surfaceAreaDoublePrime (double r)
{
return (4 * M_PI + 8000 / (r * r * r));
}
```
You might also like to view...
What is the term used to describe the event of a certificate authority canceling an issued digital certificate?
A. Destruction B. Revocation C. Expiration D. Termination
Traditionally, lists are implemented using either arrays or pointers.
Answer the following statement true (T) or false (F)