0% found this document useful (0 votes)
232 views1 page

Regula Falsi C Program

This C program uses the regula falsi method to find the root of a function. It takes initial values x0 and x1 from the user, along with an error value e. It then iteratively calculates a new value x2 using the regula falsi formula and checks if the function value at x2 is within e of zero. If not, it updates x0 or x1 based on the signs of the function values. This continues until convergence within e is reached, at which point it prints the root.

Uploaded by

Sourav Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
232 views1 page

Regula Falsi C Program

This C program uses the regula falsi method to find the root of a function. It takes initial values x0 and x1 from the user, along with an error value e. It then iteratively calculates a new value x2 using the regula falsi formula and checks if the function value at x2 is within e of zero. If not, it updates x0 or x1 based on the signs of the function values. This continues until convergence within e is reached, at which point it prints the root.

Uploaded by

Sourav Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*program for finding root using regula falsi method*/

#include<math.h>
#define f(x) x*x*x-9*x+1
int main()
{
float x0,x1,e,x2,y0,y1,y2;
int i;
printf("\n\n\t\tPROGRAM FOR FINDING ROOT USING REGULA FALSI METHOD\n\n\n");
printf("Enter the value of x0,x1,e\n");
scanf("%f%f%f",&x0,&x1,&e);
y0=f(x0);
y1=f(x1);
i=1;
if((y1!=0)&&((y0/y1)>0))
{
printf("Starting values are not correct\n\n");
printf("x0=%f,x1=%f,y0=%f",x0,x1,y0,y1);
exit(0);
}
do
{
x2=(x0*y1-x1*y0)/(y1-y0);
y2=f(x2);
i=i+1;
if((y2!=0)&&((y0/y2)>0))
{
x0=x2;
y0=y2;
}
else
{
x1=x2;
y1=y2;
}
printf("x%d = %f\n",i,x2);
}
while(fabs(y2)>e);
printf("Hence the root is %f\n\n",x2);
printf("Total number of iterations are %d",i-1);
getch();
}

You might also like