Cubic Root by Newton's Iterative Method
I have this exercise which I understand except a very small part at the end which is "for each x use e = 0.1 , 0.001, 0.00001."
Here am I required to get three cubic root values for each x and return the three values by the cubic-root function and then compare them with that value returned by the C++ normal power function??? If it is like that it seems a little bit confusing to me as why are we going to use three values for the tolerance..
The cubic root x^(1/3) of a real number x can be computed using an iterative method called Newton’s Method. In this method we start with an initial guess Y for the cubic root, and then iteratively compute better approximations using the formula:
Ynew = Y – [Y * Y – x / Y] / [ 2 Y + x / (Y * Y)]
In a given iteration, if the absolute relative difference between Ynew and Y is greater than a certain tolerance e, i.e. if | Ynew - Y | / Y > e , we repeat computing a better value Ynewotherwise we stop.
Write a function to input the real number x and the tolerance (e) and to return the cubic root of x using an initial guess of Y = x. The function should also return the number of iterations needed to achieve the final value of the cubic root.
Use a main function to test the above function by comparing its cubic root with that computed using the usual C++ power function. Choose x = 0.01 , 0.1 , 1 , 10 , 100 and for each x use e = 0.1 , 0.001, 0.00001. Also, display the number of iterations needed in each case.