//linda cobb //winter 98-99 //bisection method for finding the roots of an equation //**** caution //algorithm fails if more than one root and brackets are //symmetric.. //added in hack to correct this error corrected algorithm //finds real roots if they exist. even if there are two //roots bracketed area //no longer fails on functions such as 2x^2 +3x +1 btwn +-9 #include #include //#include extern double bisection(double x1, double x2, double error); double function(double x) { printf("\n fn %lf", 3*x + 2*x*x); return (3*x + 2*x*x); } void main (void) { //long t1,t2; double left, right, error; double solution; error = 0.0001; printf("\n Enter the left boundry => "); scanf("%lf", &left); printf("\n Enter the right boundry => "); scanf("%lf", &right); //printf("\n Enter the size of acceptable error => "); //scanf("%lf", &error); //t1 = clock(); solution = bisection(left, right, error); //t2 = clock(); printf( "\n the solution is %lf", solution); printf( "\n F of (solution) is %lf\n", function(solution)); // printf("Time = %7.2lf ms", // 1000.0*(double)(t2-t1)/(double)CLOCKS_PER_SEC); }