KEMBAR78
Program 3 | PDF
0% found this document useful (0 votes)
4 views4 pages

Program 3

The document is a C program that implements the Regula Falsi method to find the real roots of a nonlinear equation defined as f(x) = x*log10(x) - 1.2. It prompts the user for two initial guesses and the number of iterations, checks if the guesses bracket the root, and iteratively refines the guesses to converge on the root. The final output displays the estimated root after the specified iterations.

Uploaded by

Sheela Mense
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Program 3

The document is a C program that implements the Regula Falsi method to find the real roots of a nonlinear equation defined as f(x) = x*log10(x) - 1.2. It prompts the user for two initial guesses and the number of iterations, checks if the guesses bracket the root, and iteratively refines the guesses to converge on the root. The final output displays the estimated root after the specified iterations.

Uploaded by

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

/* 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

You might also like