[C con Clase] metod de biseccion, oblemas con el manejo de tipo de variables (double)

Jose Ramon Dominguez Barba josedb_90 en hotmail.com
Vie Sep 3 06:45:08 CEST 2010


Buen dia amigos.

 

Tengo un pequeño problema con un programa simple: 

 el programa trata de emplear el metodo de biseccion(es un metodo numerico), esta es una parte del programa 

 

float biseccion( double x_in,double x_fin,float e_max){
     double x_r,fx_in,fx_r,x_r2=0;
     float error=100;
     int i=0;


    while ( error>=e_max){


        x_r= x_in+x_fin/2; //obtiene punto medio Xr
        fx_in= f_(x_in); // obtien Y inicial y Y del pnt medio
        fx_r = f_(x_r);
        if (fx_in*fx_r<0) x_fin=x_r;
        else if (fx_in*fx_r>0) x_in=x_r;
        else if (fx_in*fx_r==0) break;
            break;
        
        if (x_r2!=0)
            error=(x_r2-x_r/x_r2)*100;
        if (error<0) error= -1*error;
                   //if(error==0) error=100;
        x_r2=x_r;
        i++;
    }
printf("\n =D");
    printf("La raiz de la funcion es: %lf \n Iteracion necesarias %d\n",x_r,i);
    printf("La funcion de la raiz es: %lf \n Error maximo resultante: %lf\n",fx_r,error);

}

float f_ (double x){
    double y;
    y=-2.1+6.21*x-3.9*pow(x,2)+0.667*pow(x,3);
    printf("\n -D");
    return y;
}


------se supoen que los valores se manejaran como flotantes dobles. 

 

...EL PROBLEMA ES QUE AL HACER LA PRIMER OPERACION   x_r= x_in+x_fin/2; NO DA EL RESULTADO DEBIDO

Y POR SER x_r UN VALOR QUE SE USA MAS A DELANTE TODO LO DEMAS SALE MAL......

 

.....QUE PUEDE SER EL PROBLEMA???...EL TIPO DE DECLARACION?? ... COMO SE LEEN LOS RESULTADOS??..COMO IMPRIMEN??
 		 	   		  
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20100903/d944570b/attachment.html>


Más información sobre la lista de distribución Cconclase