clear;
clc;

iterations = 5;
x = [0.4:0.0001:0.42]; % initial interval
a = 4;

finalvals = [];
for j = 1: length(x)
    xvals = [x(j)];
    yvals = [0];
    for i = 1:iterations
        x1 = quad_iterator(x(j),a);
        xvals = [xvals x(j) x1];
        yvals = [yvals x1 x1];
        x(j) = x1;
    end   
    plot(xvals, yvals, '-b', 'linewidth', 2)
    hold on
    finalvals = [finalvals x(j)];
end    


funvals = [];
for i=0:0.001:1
    funvals = [funvals quad_iterator(i,a)];
    % or sawtooth(i) or tent(i)
end

plot([0 1], [0 1] ,'k');
plot(0:0.001:1, funvals, 'k');
hold off;
ylim([0 1]);
xlim([0 1]);

disp(min(finalvals));
disp(max(finalvals));
disp(max(finalvals)-min(finalvals));