Do for me please! Heron\'s method can be extended to higher roots of a number. F
ID: 3764797 • Letter: D
Question
Do for me please! Heron's method can be extended to higher roots of a number. For example, it could be extended to the calculation of the cubic root of a number N, which means that root = 3 squareroot N (1) and (root)^3 = N (2) (For example, the cubic root of 8 is 2). The steps in the extended Moron's Method would be: Step 1: Provide an initial guess" of the root, x, at j = 0 Step 2: Calculate the number Q, defined as Q = N/xj^2Note that, if the initial guess was correct (or if we haw reached convergence), Q will have the same value as the roof. However, if it is not the root yet, it can be considered a belter approximation than xj Step 3: Calculate the "next" value of xj (at j = 1) using a weighted average: xj+1 = (2xj + Q) / 3 To close the iterative loop, we should update j ( bv doing j = j + 1) and then repeat from Step 1, until convergence is achieved. Write a C++ program that implements the extended Heron's Method described above. To test for convergence, use equation (2) as follows: Convergence will exist when abs[xj^3 - N] LE epsilion. As usual, eplision will be a very small, positive constant (use eplision =1 x 10^4 for this assignment). Your program must: Prompt the user to provide the value of N (positive or negative). Prompt the user to provide the initial guess xs. Display the new values of x, after they have been calculated in Step 3. You can test your program with the following data (it must work with any N!) N 1.860867 36.62744516 -11.089567 -0.681472 cubic root 1-23 3.321 -123 -0.88Explanation / Answer
#include <iostream>
using namespace std;
int main() {
double x[10], Q, e=0.0001, c;
int N, j;
cout<<"Enter the number: "
cin>>N;
cout<<" Evaluating cube root of "<<N<<"using Heron's Method...";
cout<<" Enter Inital Guess: ";
cin>>x[0];
for(j=0; j<=N; j++){
c = x[j]*x[j]*x[j];
if(c<=e){
cout<<"Cube root of "<<N<<" using Heron's Method is "<<x[j];
}
else{
Q = N / (x[j]*x[j]);
x[j+1] = (2*x[j]+Q)/3;
}
}
return 0;
}