Lab Report On False Position Method: Assignment 3
Lab Report On False Position Method: Assignment 3
Submitted By:
Ayush Timalsina
Jaya Multiple Campus
BCA , 4th Semester
Contents:
1. Introduction
2. Algorithm
3. Program
4. Conclusion
5. Reference
Introduction:
False position method is a root-finding algorithm that is
qualitative similar to the bisection method in that it uses intervals based
on opposite signs at the endpoints to converge to a root, but is
computationally based on the secant method.
Graphically,
In the given figure,
Let us consider a function f(x) and suppose two initial values x0 and x1
such that f(x0) f(x1)<0
Or,
F(x0) & F(x1) have opposite sign. Also the co ordinate of point A&B
are A[x1 f(x1)] and B[x0 f(x0)].
Let us draw a secant line passing through the point A&B which
intersects at the point x2 in x-axis.
Now,
Equation of the line joining the point of A & B.
Using two point formula
1. Start
2. Read the value of x0 ,x1 and e where x0 &x1 are initial guesses
and e is an error.
3. Compute f(x0) and f(x1).
4. Check if f(x0) f(x1)< 0
Go to 5
Else
Initial guesses donot bracket the root
5. Determine the value of x using
Formula:
X= x0f(x1) – x1 f(x0)
f(x1) – f(x0)
8. Stop
Program:
#include<stdio.h>
#include<math.h>
float f(float x)
{
return 4*exp(- x) * sin(x) - 1;
}
int regula (float *x, float x0, float x1, float fx0, float fx1, int *itr)
{
*x = x0 - ((x1 - x0) / (fx1 - fx0))*fx0;
++(*itr);
printf("Iteration no. %3d X = %7.5f \n", *itr, *x);
}
int main ()
{
int itr = 0, maxmitr;
float x0,x1,x2,x3,allerr;
printf("\nEnter the values of x0, x1, allowed error and maximum iterations:\n");
scanf("%f %f %f %d", &x0, &x1, &allerr, &maxmitr);
regula (&x2, x0, x1, f(x0), f(x1), &itr);
do
{
if (f(x0)*f(x2) < 0)
x1=x2;
else
x0=x2;
regula (&x3, x0, x1, f(x0), f(x1), &itr);
if (fabs(x3-x2) < allerr)
{
printf("After %d iterations, root = %6.4f\n", itr, x3);
return 0;
}
x2=x3;
}
while (itr<maxmitr);
printf("Solution does not converge or iterations not sufficient:\n");
return 1;
}
Output:
Conclusion:
Hence , The false position method is a root-
finding algorithm that combines features from the bisection method and
the secant method. It is represented graphically and systematically that I
have already mentioned above.
Reference:
https://mathworld.wolfram.com/
https://calculus.subwiki.org/