c program to implement Regular Falsi method to find the root of equation

//program to implement Regular Falsi method to find the root of equation
//f(x)=2*x-cos(x)-3=0
#include<stdio.h>
#include<conio.h>
#include<math.h>
double f(float x)
{
return(cos(x)-x*exp(x));
}
void main()
{
float a,b,c,e,del,y1,y2,y3;
clrscr();
printf("\n Enter the values of a and b : ");
scanf("%f  %f",&a,&b);
printf("\n Enter the value of epsilon : ");
scanf("%f",&e);
printf("\n Enter the value of delta : ");
scanf("%f",&del);
y1=f(a);
y2=f(b);
if((y1*y2)>0)
{
printf("\n Initial condition not suitable!!!");
}
else
{
do
{
if(fabs((double)(y2-y1))< del)
{
printf("\n approximation is too small");
}
else
{
c=(a*y2-b*y1)/(y2-y1);
y3=f(c);

if((y1*y3)<0)
{
b=c;
}
else
{
a=c;
}
}
}
while(fabs((double) (a-b)) >e) ;

printf("\n\t Approximate value is = %f",c);
}

getch();
}

Comments

Popular Posts