/* Program: Finding real roots of nonlinear
equation using Regula Falsi or False Position Method */
/* Header Files */
#include<stdio.h>
#include<conio.h>
#include<math.h>
/* Defining equation to be solved.
Change this equation to solve another problem. */
#define f(x) x*log10(x) - 1.2
int main()
float a, b, c, f0, f1, f2, i, n;
int step = 1;
/* Inputs */
up:
printf("\nEnter two initial guesses:\n");
scanf("%f%f", &a, &b);
/* Calculating Functional Value */
f0 = f(a);
f1 = f(b);
/* Checking whether given guesses brackets the root or not. */
if( f0 * f1 > 0.0)
printf("Incorrect Initial Guesses.\n");
goto up;
printf("Enter no of Iterations:\n");
scanf("%f", &n);
/* Implementing Regula Falsi or False Position Method */
printf("\nStep\t\ta\t\tb\t\tc\t\tf(c)\n");
for(i=1;i<=n;i++)
c = a - (a-b) * f0/(f0-f1);
f2 = f(c);
printf("%d\t\t%f\t%f\t%f\t%f\n",step, a, b, c, f2);
if(f0*f2 < 0)
b = c;
f1 = f2;
else
a = c;
f0 = f2;
}
step = step + 1;
printf("\nRoot is: %f", c);
return 0;
[?2004l
Enter two initial guesses:
2 1 2
Incorrect Initial Guesses.
Enter two initial guesses:
23
Enter no of Iterations:
Step a b c f(c)
1 2.000000 3.000000 2.721014 -0.017091
2 2.721014 3.000000 2.740206 -0.000384
3 2.740206 3.000000 2.740636 -0.000009
Root is: 2.740636