#include <stdio.h>
#include <math.h>
#define PI 3.1415926535897931
#define e 2.71828
#define thshold 2 * pow(10,-4)
double fx(double x)
{
return (7*sin(x) * pow(e,(-x)) -1);
}
void Secant_Method(double xl, double xu)
{
double a,b,fa,fb,p;
double sol;
int i=0;
double eia=100;
double eit;
a = xl;
b = xu;
fa=fx(a);
fb=fx(b);
while(1)
{
p=b-fb*(b-a)/(fb-fa);
eia = fabs((b-a)/b)*100;
if(eia<thshold)
{
sol = p;
break;
}
i++;
a=b;
fa=fb;
b=p;
fb=fx(p);
}
eia = 100;
a = xl;
b = xu;
fa=fx(a);
fb=fx(b);
while(1)
{
p=b-fb*(b-a)/(fb-fa);
eia = fabs((b-a)/b)*100;
eit = fabs((sol-b)/sol)*100;
printf("%d a=%lf\t b=%lf\t eai = %lf\t eti = %lf\n",i,a,b,eia,eit);
if(eia<thshold)
{
printf("x=%lf\n",p);
break;
}
i++;
a=b;
fa=fb;
b=p;
fb=fx(p);
}
}
int main(void)
{
Secant_Method(0.4,0.5);
return 1;
}