# MATLAB Code for Regula Falsi (False Position) Method with Output

#### MATLAB program for finding real root of non-linear equation using Regula Falsi Method with Output. Regula Falsi method is also known as False Position Method.

In this MATLAB program for false position method, y is nonlinear function, a & b are two initial guesses and e is tolerable error.

## MATLAB Source Code: Regula Falsi Method

``````
% Clearing Screen
clc

% Setting x as symbolic variable
syms x;

% Input Section
y = input('Enter non-linear equations: ');
a = input('Enter first guess: ');
b = input('Enter second guess: ');
e = input('Tolerable error: ');

% Finding Functional Value
fa = eval(subs(y,x,a));
fb = eval(subs(y,x,b));

% Implementing Bisection Method
if fa*fb > 0
disp('Given initial values do not bracket the root.');
else
c = a - (a-b) * fa/(fa-fb);
fc = eval(subs(y,x,c));
fprintf('\n\na\t\t\tb\t\t\tc\t\t\tf(c)\n');
while abs(fc)>e
fprintf('%f\t%f\t%f\t%f\n',a,b,c,fc);
if fa*fc< 0
b =c;
fb = eval(subs(y,x,b));
else
a =c;
fa = eval(subs(y,x,a));
end
c = a - (a-b) * fa/(fa-fb);
fc = eval(subs(y,x,c));
end
fprintf('\nRoot is: %f\n', c);
end
``````

## Regula Falsi MATLAB Output

```Enter non-linear equations: sin(x)+cos(x)+exp(x)-8
Enter first guess: 2
Enter second guess: 3
Tolerable error: 0.00001

a		b		c		f(c)
2.000000	3.000000	2.010374	-0.054516
2.010374	3.000000	2.015152	-0.025119
2.015152	3.000000	2.017349	-0.011551
2.017349	3.000000	2.018358	-0.005306
2.018358	3.000000	2.018821	-0.002437
2.018821	3.000000	2.019034	-0.001119
2.019034	3.000000	2.019132	-0.000514
2.019132	3.000000	2.019177	-0.000236
2.019177	3.000000	2.019197	-0.000108
2.019197	3.000000	2.019207	-0.000050
2.019207	3.000000	2.019211	-0.000023
2.019211	3.000000	2.019213	-0.000010

Root is: 2.019214
```