I am trying to do Newton's method. What is wrong with my code? The while loop is not executing correctly. The value of the currNextRatio that terminates the while loop is still well above where it is required to be when the program finishes. I have left in my tests.
Enter the degree of the highest degree term: 2
Enter the coefficient of the next highest degree term: 5
5x^2
Enter the coefficient of the next highest degree term: 4
4x^1
Enter the coefficient of the next highest degree term: 3
3x^0
5x^2 + 4x^1 + 3
Guess a root. The computer will find the root closest to this number. 6
nextValue: 2.76562, currValue: 6
m
The closest root to that value is
2.76562
nextValue: 2.76562, currValue: 6 ratio: 0.539062
Process returned 0 (0x0) execution time : 12.927 s
Press any key to continue.
The two pieces which do not match are the while loop while (abs(currNextRatio - 1.0) > 0.00001)
and the ratio output which is the final value of currNextRatio ratio: 0.539062
is abs() making an int out of my float?
Yup. Strange how asking a question can somehow help to see the problem. Though I think I still have my math wrong.
I have now replaced #include <stdlib.h>
with #include <cmath>
to get abs to work with a float.
I was also wrong in thinking I needed a ratio for the while loop. All I needed to do was take the abs of the difference between currValue and nextValue.