%% NEWTON'S METHOD: EX 2
%(Selcuk Bayin, METU-NCC, bayin@metu.edu.tr)
clc
disp('EX 1:   Solve 0 = x^2-3x+1')
f = inline('x.^2 - 3*x + 1', 'x')   
df = inline('2*x - 3', 'x')       
%%
fprintf('--------\nInitial guess:')
x = 1
iteration=0;
while ((iteration < 1000) && (abs(f(x)) > .00001))
    x = x - f(x)./df(x); 
    iteration = iteration + 1;
end
disp('Result:')
disp('       x      error   iteration')
disp([x, abs(f(x)), iteration])
%%
fprintf('--------\nInitial guess:')
x = 3
iteration=0;
while ((iteration < 1000) && (abs(f(x)) > .00001))
    x = x - f(x)./df(x); 
    iteration = iteration + 1;
end
disp('Result:')
disp('       x      error   iteration')
disp([x, abs(f(x)), iteration])




