%computer problem 3.2 #7

f = @(x) 1-x^2;
f_p = @(x) -2*x;
n = 3;

%do h/2-modified Newton method

x = 0.1;
for i=1:n
    h = f(x)/f_p(x);
    if abs(f(x-h)) >= abs(f(x))
        h = h/2;
    end
    x = x-h;
end
disp('modified Newton method root estimate is...')
x

%compare to standard Newton method

x=0.1;
for i=1:n
    h = f(x)/f_p(x);
    x = x-h;
end
disp('standard Newton method root estimate is...')
x