The cubic root of a number P can be calculated by using an i

The cubic root of a number, P, can be calculated by using an iterative approximation. Squareroot P = x_i = 1 = (P/x_i + 2x_i)/3 where x_i is the previous approximation and x_i + 1 is the current approximation. Write a tor-loop to calculate the cubic root of 100, using 10 iterations. Begin with an initial approximation of xt = P Print out the final value and the final absolute true error, E_T = 3Cuberoot 100 - x_10.

Solution

PROGRAM CODE:

#include <iostream>
#include <cmath>
using namespace std;

double cubicRoot(double number)
{
   double result = number;
   double doubleValue = number;
   for(int i=0; i<10; i++)
   {
       result = (number/doubleValue + (2*result))/3;
       doubleValue = result*result;
   }
   cout<<\"Result of Iteration: \"<<result<<endl;
   cout<<\"Actual Result: \"<<pow(number, 1.0/3.0)<<endl;
   cout<<\"Absoluet true error: \"<< abs(pow(number, 1.0/3.0) - result);
}

int main() {
   cubicRoot(100);
   return 0;
}

OUTPUT:

 The cubic root of a number, P, can be calculated by using an iterative approximation. Squareroot P = x_i = 1 = (P/x_i + 2x_i)/3 where x_i is the previous appro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site