#include<iostream.h>
#include<math.h>
float f(float x)
{
return(2*x-log10(x)-7);
}
void main()
{
float x1,x2,h,e;
int k=0;
cout<<"X1=";
cin>>x1;
cout<<f(x1);
cout<<"\nX2=";
cin>>x2;
cout<<f(x2);
cout<<"\nEpsilon=";
cin>>e;
do
{ k++;
h=((x2-x1)*fabs((f(x1)))/(fabs(f(x1))+fabs(f(x2))));
x1=x1+h;
if(h<0)
h=-h;
else
cout<<"\nk="<<k<<"\tx1="<<x1<<"\tf(x1)="<<f(x1)<<"\th="<<h;
cout<<endl;
}while(h>e);
cout<<"\nThe result is="<<x1;
}
#include<math.h>
float f(float x)
{
return(2*x-log10(x)-7);
}
void main()
{
float x1,x2,h,e;
int k=0;
cout<<"X1=";
cin>>x1;
cout<<f(x1);
cout<<"\nX2=";
cin>>x2;
cout<<f(x2);
cout<<"\nEpsilon=";
cin>>e;
do
{ k++;
h=((x2-x1)*fabs((f(x1)))/(fabs(f(x1))+fabs(f(x2))));
x1=x1+h;
if(h<0)
h=-h;
else
cout<<"\nk="<<k<<"\tx1="<<x1<<"\tf(x1)="<<f(x1)<<"\th="<<h;
cout<<endl;
}while(h>e);
cout<<"\nThe result is="<<x1;
}
No comments:
Post a Comment