%% Graphical search
% 
% Finding roots of function $f(x) = sin(10x)+cos(3x)$
% graphically:
x = linspace(3,6);
plot(x,sin(10*x)+cos(3*x))
grid
xlabel('x')
ylabel('f(x)')


%% Incremental search 
% First, using the default number (50) intervals
%
r = incsearch(@(x) sin(10*x)+cos(3*x),3,6)

%%
% or using user-defined function fun1.m
%
incsearch(@fun1,3,6);

%%
% Add the intervals that were found to the plot.
hold on
plot(mean(r'),zeros(size(mean(r'))),'r.','MarkerSize',6)

%%
% Note how roots near 4.3 and 5.2 were missed.
% Use the zoom tool to convince yourself that there are roots indeed.
%
% Now double the number of intervals.
%
r2 = incsearch(@(x) sin(10*x)+cos(3*x),3,6,100)

plot(mean(r2'),zeros(size(mean(r2'))),'k.','MarkerSize',6)