I have to write a C++ code that has to satisfy the following and i have no idea
ID: 3546106 • Letter: I
Question
I have to write a C++ code that has to satisfy the following and i have no idea how to do it, Ive started it and done it several different ways but none of them work out, please help.
To calculate an approximation of the value , a > 0, you can use the following iterative formula:
xn+1 = 1/3(2xn + a/x^2n) , n >= 0
The approximation of a^1/3, is obtained through the sequence x0, x1, x2......xk starting with x0 = a.
The iteration should stop when the following condition is satisfied:
or the number of the iteration is greater than 20.
Write a program that prints out the following table:
where:
- The numbers of the 2nd column are calculated using the iteration formula (1).
- The 3rdcolumn is the corresponding values of the function pow from cmath library.
Note: The numbers in the 2nd and 3rd columns should be printed out by using the manipulator setprecision (5).
Input data: No input data
Output: The table from the above
Explanation / Answer
int main()
{
double E, x, y, a, c;
a = 0.5;
x = a;
y= a;
E = pow ( 10.0, -5);
while (a < 20 && abs((x -y)/x) <= E)
{x = (1.0/3.0)*(2*x+a/(pow(x,2.0)));
c = pow(a, 1.0/3.0);
a += .5;
y = x;
cout << a << " " << x << " " << c << endl;}}