clear all;close all;
f = @(x) x.^2-2;
fp = @(x) 2.*x;
x = 1;
k = 1;
d = 1;
fprintf('%20s %20s %20s\n','k','zero','deviation') ;
x1 = 1; x2 = 2; f1=f(x1); f2=f(x2);
if(f1*f2>0) 
    disp('bad guess for initial x1,x2')
    break;
end
while abs(d)>10^-10
    x = 0.5*(x1+x2);
    ff=f(x);
    if ff*f1<0
        x2=x;
        f2=ff;
    else
        x1=x;
        f1=ff;
    end
    d = abs(x2-x1);
    fprintf('%20d %20.15f %20.15f\n',k,x,d);
    k = k+1;
end
