% Newton method for scalar equations
f  = @(x) x*x; %exp(-x) - x;
df = @(x) 2*x; %-exp(-x) - 1;
format long

d = 1.0E-20; % stoppparamameter
x = 1.5; % startgissning
max = 20; % max iterations

while(abs(f(x)) > d && max>0)
    x = x - f(x)/df(x);
    fprintf('%.10f\n', x) 
    max=max-1;
end