To use this method it is necessary to know the interval where the function f cuts to the x axis, since this method joins with a line where the two extremes of the interval are represented in the function,so a line passes through two points that are in the function f, this line will necessarily cut the x axis,This point where cut is x which we will evaluate in the function to see if it gives 0 (root), if it is not the case then with this new x we will form an interval with one of the extremes of the previous interval, it is chosen depending on where the change of sign is with respect to x. This is why the name, because where you cut the created line may or may not be the true position.
PSEUDOCÓDE
Read Xi, Xs, Tolerance, Iter
Yi = f (Xi)
Ys = f (Xs)
If Yi = 0 Then
Show: 'Xi is Raiz'
If not
If Ys = 0 Then
Show: 'Xs is Raiz'
If not
If Yi * Ys <0 Then
Xm = Xi - ((Yi * (Xs - Xi)) / (Ys - Yi))
Counter = 1
Ym = f (Xm)
Error = Tolerance + 1
While Error> Tolerance & Ym ~ = 0 & Counter <Iter
If Yi * Ym <0 Then
Xs = Xm
Ys = Ym
If not
X i = Xm
Yi = Ym
End if
Xaux = Xm
Xm = Xi - ((Yi * (Xs - Xi)) / (Ys - Yi))
Ym = f (Xm)
Error = Abs (Xm - Xaux)
Counter = Counter + 1
End While
If Ym = 0 Then
Show: 'Xm is Root'
But If Error <Tolerance Then
Show: 'Xm is approximation to a root with tolerance' Tolerance ''
If not
Show: 'Failure in' Iter 'iterations'
End if
End if
End if
End if
End if
End Process
FALSE RULE CODE
clc
clear
fprintf ('false rule method');
disp ('');
f = input ('enter the function to evaluate f =', 's');
function = inline (f);
a = input ('enter interval less than =');
b = input ('enter upper interval b =');
tol = input ('define a tolerance =');
n = ceil (log ((b-a) / tol) / log (2)) + 2;
f1 = function (a);
f2 = function (b);
if f1 == 0
fprintf ('the root was found at a =% d', a);
elseif f2 == 0
fprintf ('the root was found in b =% d', b);
elseif f1 * f2> 0;
fprintf ('no root was found in the interval');
disp ('');
elseif f1 * f2 <0
pm = a - ((function (a) * (b-a)) / (function (b) -function (a)));
f3 = function (pm);
error = tol +1;
iter = 0;
fprintf ('n a b pm f3 error \ n')
cont = 1;
while iter <= n && f3 ~ = 0 && error> tol
fprintf ('% g% f% f% f% f% f \ n', iter, a, b, pm, f3, error)
if f1 * f3 <0
b = pm;
else
a = pm;
end
aux = pm;
pm = a - ((function (a) * (b-a)) / (function (b) -function (a)));
error = abs (pm-aux);
iter = iter +1;
f3 = function (pm);
end
disp ('');
fprintf ('% g% f% f% f% f% f \ n', iter, a, b, pm, f3, error)
disp ('');
if f3 == 0;
fprintf ('the root is pm =% f and it was found in the error =% f \ n', pm, error);
elseif error <tol
fprintf ('an approximation to the root was found in pm =% f and found in the error =% f \ n', pm, error);
else
fprintf ('the failure process')
end
end