The objective of the method is to find an interval which contains at least one root.
For this, the method is based on the intermediate value theorem.
Intermediate value theorem: If f is a continuous function in the interval [a, b] and k is any number between f (a) and f (b), then there exists a number c in the interval (a, b) such that f (c) = k.
Bolzano's theorem: If f is a continuous function in [a, b] with f (a) and f (b) of opposite signs (f (a) * f (b) <0), then there is at least one c ε (a, b) such that f (c) = 0.
That is to say:
· If a continuous function in [a, b]
· If f (a) * f (b) <0
So:
There exists c ε (a, b) such that f (c) = 0
PSEUDOCODE
write (' method of Incremental search ')
write ('This method finds intervals where there is a root, root or both')
write ('The method will not print anything if there is no root in the given interval')
read fx, x0, xN, h
fx = convert the input fx of the user to function
graph fx
for n = x0 to xN-h pace = h
a = fx (n + h) * fx (n)
if a <0 then
write ('There is a root between the closed interval that goes from n to n + h')
else if fx (n) == 0
write ('This number is a root: n')
end if
end for
if fx (xN) == 0 then
write ('This number is a root: xN')
end if
CODE
clc
clear all
disp ('Incremental search method');
disp ('This method finds intervals where there is a root, the root or both')
disp ('The method will not print anything if in the given interval there is no root')
fx = input ('Enter the function:', 's');
x0 = input ('Enter the initial value of the interval:');
xN = input ('Enter the final value of the interval:');
h = input ('Enter step:');
fx = inline (fx);
fplot (fx, [x0 xN])
grid on
for i = x0: h: xN-h
a = fx (i + h) * fx (i);
if a <0
disp ('There is a root between the closed internalo that goes from ... to ...')
disp (i)
disp (i + h)
elseif fx (i) == 0
disp ('This number is a root:'); disp (i)
end
end
if fx (xN) == 0
disp ('This number is a root:'); disp (xN)
end