I am trying to create a C++ program that can calculate cube root. I was assigned to use the Newton-Raphson cube root. A website that speaks about it can be found here:
http://www.mathpath.org/Algor/cuberoot/cube.root.newton.htm

Here is my overview taken from that website:

X2 = 2(X1)+a(X1^2)
___________
3

My writing of the formula is pretty rough. Please go on the website above, if you want to see what the formula is actually supposed to look like.

X2 is the next number used in the formula
X1 is the initial guess of the cube root (can be anything – I am using 1)
a is the number we are taking the cube root of

Here is how it plays out for the cube root of 100.

X2 = 2(1)+100(1^2)
___________
3
X2 = 2+100
___________
3
X2 = 102
___________
3

X2 = 34

Now, we are supposed to substitute the X2 we got into the X1 spot and repeat.

X2 = 2(34)+100(34^2)
___________
3
X2 = 68+100/1156
___________
3
X2 = 68.08
___________
3
X2 = 22.69

There is a rule that states every time that you repeat, this occurs: The if you take the difference of the old X1 and the new X1, in this case, 34 and 22.69 which is 11.31, the actual cube root is within 11.31 of the new X1. This means the cube root of 100 should like within 11.31 away from 22.69. It does not. The cube root of 100 is 4.64 which is about 16 away. This is breaking one of the laws that has been used for 100s of years. My program is getting results that are incorrect. Something has gone askew with this.

Can you identify the problem? Is the formula that I got wrong? Am I solving the formula wrong? What has gone askew for these results to occur? My teacher did not have a response, when we showed him this. Please give me any and all information you have about this. Thanks.

http://babbage.clarku.edu/~djoyce/newton/method.html - Please go to that site as it is a very good background for this. I did not examine this site in full yet. I am doing so now. I think it is a good resource. Thanks again.

Newton-raphson iterative formula for f(x)=0; is
x2=x1-f(x1)/f'(x1);
u have to find the root of (x^3)-a=0;
so the formula is x2=x1-((x1^3)-a)/(3x1^2);
orx2=(2x1+a/x1^2)/3;
In other words u got ur formula wrong.

Now let us do the 100 prob with this formula-
assume x=1

after Pass 1 x= 34
Pass2 x=22.695501
Pass3 x=15.195048
Pass4 x=10.274402
Pass5 x=7.165367
Pass6 x=5.426147
Pass7 x=4.749559
Pass8 x=4.644025
Pass9 x=4.64159
Pass10 x=4.641589

Hope that clears ur prob.

Member Avatar for iamthwee

Erm do you know what differentiation is?

Ok you wanna find the cube root of 100... Therefore you can say:-

x^3 = 100

In order for you to use that in newton's raphson formula you gotta rearrange it so that zero is equal to something.

0 = 100 - x^3

So
f_x = 100 - x^3
and
f'_x = -3x^2 basic calculus. The f' means differentiate the function f(x)

Now you can apply that to the newton raphson formula:

x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}

Thus:-

x_{n+1} = x_n - \frac{100-x^3}{-3x^2}

//newton raphson for x^3

#include <iostream>
#include <string>

using namespace std;

int main()
{
    double x = 5000.0; //arbitary starting value
    double value = 100.0; //Value you want to find cube root of
    
    for ( int i = 0; i < 100; i++ )
    {
      x = x - ( ( value - x*x*x ) / (-3*x*x ) );
      cout << x << endl;   
    } 
    cout << x;
    cin.get();
}

I hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.