Table of Contents

## Method of False Position

**Regula-Falsi method** also called the **Method of False Position**, closely resembles the Bisection method.

This is the oldest method of finding the real root of an equation.

## Regula Falsi Method C++ Program

```
//Regula Falsi method
//wikkihut.com
#include<iostream>
#include<math.h>
using namespace std;
float f(float x)
{
return cos(x)-x*exp(x);
}
void regula (float *x, float x0,float x1, float fx0,float fx1, int *itr)
{
*x=x0-((x1-x0)/(fx1-fx0))*fx0;
++(*itr);
}
int main()
{
int itr=0, maxitr;
float x0,x1,x2,x3,aerr;
cout<<"Enter the values of x0,x1, allowed error , maximum iterations"<<endl;
cin>>x0>>x1>>aerr>>maxitr;
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)<aerr)
{
cout<<"After "<<itr<<" iterations, root = "<<x3<<endl;
return 0;
}
x2=x3;
}
while(itr<maxitr)
cout<<"Solution does not converge"<<endl;
cout<<"Iterations are not sufficient"<<endl;
return 1;
}
```

Code language: PHP (php)

## Example

#### Find the Roots of *f(x)=x*^{3}-2x-5

*f(x)=x*

^{3}-2x-5let **f(x)=x ^{3}-2x-5** and we have to find its real root correct to three decimal places.

if we put ** x=2** and

**, we find**

*x=3**is negative and*

**f(2)****is positive.**

*f(3)*it means the root lies between 2 and 3.

therefore, taking* x _{0} = 2 x_{1} = 3 f ( x_{0 } ) = -1* and

*f ( x*

_{1 }) = 16in equation (2) we get

**x**

_{2}= 0.0588**Now f(x _{2}) = f( 0.0588 ) = -0.3982**

i.e., the root lies between 2.0588 and 3.

Therefore, taking

x_{0} = 2.0588

x_{1} = 3

f ( x_{0 }) = -0.3908

f ( x_{1 }) = 16 in eq. (2)

we get, **x _{3} = 2.0813**

By repeating this process, the successive approximations are

x_{4}=2.0682 x_{5}=2.0915

.

.

.

x_{7}=2.0941 and

x_{8}=2.0943

and therefore the root is **2.094** .

*Suggested Read:*

## Graphical explanation.

As in picture we use two points ** x_{0 }**and

**such that**

*x*_{1}*and*

**f(x**_{0})

*have opposite sign,*

**f(x**_{1})that is the graph

*y=f(x)*cuts the

*x-axis*at least once while going from

**to**

*x*_{0}**, which indicates that the root lies between**

*x*_{1}**and**

*x*_{0}**.**

*x*_{1}Now we connect the two points ** f(x_{0})** and

**by a straight line.**

*f(***)***x*_{1}The equation of straight line joining these points is :

This straight line cuts the ** x-axis **at point x

_{2},

this point where the line

**cuts the**

*(1)***is taken as an approximation to the root.**

*x-axis* At this point * Y=0 *and

**put value of**

*X=x*_{2},**and**

*Y***in (1) we get:**

*X*which is an approximation to the root. see more

Find ** f(x_{2})**.

If

**and**

*f(x*_{2})**are of opposite signs then we replace**

*f(x*_{0})**by**

*x*_{1}**and draw a straight line connecting**

*x*_{2}**to**

*f(x*_{2})

*f(x*_{0})to find the new intersection point.

If *f(x_{2})* and

**are of the same sign then**

*f(x*_{0})**is replaced by**

*x*_{0}**and proceed as before.**

*x*_{2}In both cases the new interval of search is smaller than the initial interval and ultimately convergence is guaranteed.

## Algorithm for Regula-falsi method:

- read x0,x1,e,n

remarks: x0 and x1 are two initial guesses to the root such that sign of f

therefore, taking

x0=2.0588

x1=3

f(x0)=-0.3908 and

f(x1)=16, in equation (2) we get

x3=2.0813

- (x0) and f(x1) are not same.
- f0=f(x0)
- f1=f(x1)
- for i=1 to n in steps of 1 do
- x2=(x0f1-x1f0)/(f1-f0)
- f2=f(x2)
- if |f2|<e then
- begin Write ‘convergent solution’, x2,f2
- stop end
- if sign (f2)=sign f(0)
- then begin x0=x2
- f0=f2
- else begin x1=x2
- f1=f2
- end
- endfor
- write ‘Does not converge in n iterations’
- write x3,f2
- stop