false position Algorithm
In mathematics, the regula falsi, method of false position, or false position method is a very old method for solve an equation in one unknown, that, in modify form, is still in purpose. In simple terms, the method is the trial and mistake technique of use test (The simple false position technique is found in cuneiform tablets from ancient Babylonian mathematics, and in papyri from ancient Egyptian mathematics.
Within the tradition of medieval Muslim mathematics, double false position was known as hisāb al-khaṭāʾayn (" reckoning by two errors").Regula Falsi looks as the Latinized version of rule of false as early as 1690.Several 16th century European writers feel the need to apologize for the name of the method in a science that seeks to find the truth.
%The basic idea behind the false position method is similar to the bisection
%method in that we continuously shrink the interval the root lies on until
%the algorithm converges on the root. Unlike the bisection method, the false
%position method does not halve the interval with each iteration. Instead of
%using the midpoint of a and b to create the new interval, the false position
%method uses the x-intercept of the line connecting f(a) and f(b). This
%algorithm converges faster than the bisection method.
%INPUTS:
%Function handle f
%endpoint a
%endpoint b
%maximum tolerated error
%OUTPUTS:
%An approximated value for the root of f within the defined interval.
%Written by MatteoRaso
function y = false_position(f, a, b, error)
if ~(f(a) < 0)
disp("f(a) must be less than 0")
elseif ~(f(b) > 0)
disp("f(b) must be greater than zero")
else
c = 100000;
while abs(f(c)) > error
%Formula for the x-intercept
c = -f(b) * (b - a) / (f(b) - f(a)) + b;
if f(c) < 0
a = c;
else
b = c;
endif
disp(f(c))
endwhile
x = ["The root is approximately located at ", num2str(c)];
disp(x)
y = c;
endif
endfunction