Está en la página 1de 7

Diagrama de flujo del mtodo de la regla falsa.

x1, x2, Eps, nit

y1= f(x1)
y2= f(x2)
y1*y2 > 0.0
No

Si

Error en el
intervalo

Return (0)

x1

x2

x3

xi+1-xi

y1

y2

y3

ea

y1==y2
Si

No

No se puede
dividir por cero

Return (0)

x3= x2-[y2*(x1-x2)/(y1-y2)]

y3=f(x3)

Si

y3==0

No

res=x3
Return (0)
El proceso
converge res=
res
2
yy11*y
==y
>0
23 2
No se puede
dividir por cero
y1= f(x1)
x1
x
x
xi+1
-xi
y1
31
i<=nit;
x1=x32 for3 (i=2;
=x
y2x=4i=1
f(x32) i++)

y
y
ea
x22Return
=x3 3 (0) 54

Si

No

No

Si

x3= x2-[y2*(x1-x2)/(y1-y2)]
y3=f(x3)

y3==0

Si

No

res=x3
Return (0)

El proceso
converge res=
res

ea= |(x3-x4)/(x3)|*100

x1

x2

x3

xi+1-xi

y1

y2

|x3-x4|<=Eps

Si

y3

ea

No

res=x3
break
El proceso
converge res=
res

Si

x1=x3

y1*y3> 0

x4=x3

No

x2=x3

Si

|x3-x4|>Eps

El sistema no
converge

fin

Cdigo de programacin del mtodo de la regla falsa

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

No

using namespace std;


#define f(x)(4.0*pow(x,3)-30.0*pow(x,2)+70.0*x-50.0)
main()
{
int i,nit;
float x1,x2,x3,x4,y1,y2,y3,eps,ea,res;
printf("Programa para encontrar la raiz usando la regla falsa\n");
printf("\n");
printf("x1= ");scanf("%f",&x1);
printf("x2= ");scanf("%f",&x2);
printf("eps= ");scanf("%f",&eps);
printf("nit= ");scanf("%f",&nit);
printf("\n");
y1=f(x1);
y2=f(x2);
if (y1*y2>0)
{
cout<<"\nError en el intervalo"<<endl;
return(0);
}
if (y1==y2)
{
cout<<"\nNo se puede dividir por cero\n"<<endl;
return(0);
}
x3=x2-y2*(x1-x2)/(y1-y2);
y3=f(x3);
if (y3==0)
{
res=x3;
cout<<"\nSe encontro la raiz en el primer intervalo\n"<<endl;
return(0);
}
i=1;
cout<<"it"<<" "<<" x1"<<" "<<" x2"<<" "<<" x3"<<" "<<" |xi+1-xi|"<<" "<<" ea
%"<<" "<<" y1"<<" "<<" y2"<<" "<<" y3"<<endl;
printf("\n");
printf("%2d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f\n",i,x1,x2,x3,y1,y2,y3);
if (y1*y3>0)
x1=x3;
else
x2=x3;
x4=x3;

for (i=2;i<=nit;i++)
{
y1=f(x1);
y2=f(x2);
if (y1==y2)
{
cout<<"\nNo se puede dividir por cero\n"<<endl;
return(0);
}
x3=x2-y2*(x1-x2)/(y1-y2);
y3=f(x3);
if (y3==0)
{
res=x3;
cout<<"\nEl proceso converge res= "<<res<<"\n"<<endl;
return(0);
}
ea=fabs((x3-x4)/x3)*100;
printf("%2d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f\n",i,x1,x2,x3,fabs(x4x3),ea,y1,y2,y3);
if (fabs(x3-x4)<=eps)
{
res=x3;
cout<<"\nEl proceso converge res= "<<res<<"\n"<<endl;
break;
}
if (y1*y3>0.0)
x1=x3;
else
x2=x3;
x4=x3;
}
if (fabs(x3-x4)>eps)
cout<<"\nEl sistema no converge\n"<<endl;
printf("\n");
system("pause");
}

También podría gustarte