C Program of Regular-Falsi Method
In this article we will see C Program of Regula-Falsi Method i.e. how to solve the algebraic and transcendental equations using Regula-Falsi Method or False position method.
The Regula–Falsi Method is a numerical method used for calculating the roots of a polynomial f(x). A value x replaces the midpoint in the Bisection Method and serves as the new approximation of a root of f(x).
We will see a C program for finding a real root of the equation x2+x-1=0 by using Regula-falsi (False Position) Method in the interval [0,1] correct upto three decimal places.
C Program of regula-falsi method
/* Exp.No 2: Regula-Falsi Method (Finding the roots of given Equ.) */ #include<stdio.h> #include<conio.h> #include<math.h> #define f(x) x*x+x-1 int main() { float x0,x1,x2, y0,y1,y2, e; int maxitr,i; printf("Enter two initial starting roots \n"); scanf("%f%f",&x0,&x1); printf("Enter maximum iteration \n"); scanf("%d",&maxitr); printf("Enter the tolerance value \n"); scanf("%f",&e); y0 = f(x0); y1 = f(x1); if (y0*y1 > 0.0) printf("Initial roots are unsuitable \n"); else for(i=1;i<=maxitr;i++) { x2 = (x0*y1-x1*y0)/(y1-y0); y2 = f(x2); if (fabs(y2) < e) { printf("\nsolution is converge \n"); printf("\nRoot of the given equ.is = %9.4f\n",x2); maxitr=i; } else if(y2*y0 < 0) { x1=x2; y1=y2; } else { x0 = x2; y0 = y2; } } return 0; }
OUTPUT
Enter two initial starting roots 0 1 Enter maximum iteration 10 Enter the tolerance value 0.0001 solution is converge Root of the given equ.is = 0.6180
You may also practice :-
- Write a C program for finding a real root of the equation x6-x4-x3-3 = 0 in the interval 1.5 and 1.6 correct up to four decimal places.
- Write a C program for finding a real root of the equation x3-x2-1 = 0 in the interval 1 and 2 correct up to four decimal places.
You might also Like :-
Best platform to learn C program. Me ever want to learn it.
Many thanks.