Documentos de Académico
Documentos de Profesional
Documentos de Cultura
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <iomanip>
#include <stdio.h>
main ()
{
int nit,con;
float x1, x2, Eps, raiz;
if (bis (x1,x2,Eps,nit,&raiz)==1)
{
cout<<"\t \n El sistema converge, Raiz = "<<raiz<<endl;
cout<<"\n"<<endl;
system("pause");
}
else
{
cout<<"\t \n El sistema no converge "<<endl;
cout<<"\n"<<endl;
system("pause");
}
}
int bis(float x1, float x2, float Eps, int nit, float *raiz)
{
int con,i;
float x3,x4,Ea,y1,y2,y3;
con=0;
for(i=1;i<=nit;i++)
{
x3=(x1+x2)/2;
y1=pol(x1);
y2=pol(x2);
y3=pol(x3);
if (pol(x3)==0)
{
*raiz=x3;
con=1;
break;
}
if (i==1)
{
printf("\t \n %2d %8.4f %8.4f %8.4f \t \t \t %8.4f %8.4f %8.4f",i,x1,x2,x3,y1,y2,y3);
}
else
{
Ea=fabs((x3-x4)/x3)*100;
printf("\t %2d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f
%8.4f",i,x1,x2,x3,fabs(x3-x4),Ea,y1,y2,y3);
if(fabs(x3-x4)<=Eps)
{
*raiz=x3;
con=1;
break;
}
}
x4=x3;
if(pol(x3)*pol(x1)>0)
{
x1=x3;
}
else
{
x2=x3;
}
}
if(con==1)
{
return (con);
}
}
float pol(float x)
{
return (4.0*pow(x,3)-30.0*pow(x,2)+70.0*x-50.0);