You are on page 1of 3

#include

#include
#define CERO 0.000000001

/*Funcion que queremos aproximar*/


float f(float x){
return (x*x*x*x*x)+(x*x)-9;
}

/*Derivada de la función a aproximar*/


float df(float x){
return (5*(x*x*x*x)+2*x);
}

float Newton_Rapson(float p, float tol, int n){


int i=0;
float np;
np=p;

if(fabs(df(p))>CERO)
p = p-(f(p)/df(p));

while ((fabs(np-p) > tol) && (fabs(f(p)) > CERO) && (i


i++;
np=p;
if(fabs(df(p))>CERO)
p =p-(f(p)/df(p));
}

if (i==n)
printf("\nSe alcanzo el numero maximo de iteraciones.\n");

return(p);
}

int main()
{
float sol;
sol=Newton_Rapson(1.5, 0.001, 50);
printf("\nLa solucion a Newton-Raphson es la raiz: %f\n", sol);
return 0;
system ("pause");
}

You might also like