/**************************************************************** * Program to find roots of x^3 - x^2 - 2 = 0 * * using the newtonian method * * David Longbottom * ****************************************************************/ #include #include #include float f(float); int main ( int argc, char *argv[] ) { float x; int i; x=1.0; //don't start at 0.0! for (i=0; i<10; i++) { x = f(x); printf("x%i = %f\n",i,x); } return (EXIT_SUCCESS); } float f(float x) { // returns x - (x^3 - x^2 -2)/(2x^2 - 2x) return x - (pow(x,3)-pow(x,2)-2)/(3*pow(x,2) - 2*x); }