jueves, 24 de enero de 2008

Método de la Bisección en Lenguaje C

#include
#include

#define Cero 0.00001

float f(float x){
return (x*x*x)-27;
}

float biseccion (float a,float b, float tol){
float c = (a+b)/2.0;

while ( (f(c) != Cero) && ( fabs(b-a) > tol ) ){
if (f(a) * f(c) < Cero)
b=c;
else
a=c;
c = (a+b)/2.0;}
return c;
}

int main(){

printf("el valor de la raiz es: %f \n", biseccion (0.0, 3.0, 0.001) );
return 0;

}

No hay comentarios: