function [x_star fvertek iter] = nl_newton_sima
%Newton-modszer

%a program akkor all le, ha |f(x_n)| eleg kicsi, bar altalaban ennel jobb 
%leallasi kriterium az, ha |x_{n+1}-x_n| eleg kicsi.

f = @(x)(x.^3-x-2);
f_der = @(x)(3*x.^2-1);
hiba = 1e-10;
maxit = 50;

%Newton-modszer
x(1) = 2;
y = f(x(1));
it = 0;
while ((abs(y) > hiba) && (it < maxit))
    it = it + 1;
    x(it+1) = x(it) - f(x(it))/f_der(x(it));
    y = f(x(it+1));
end
x_star= x; 
iter = it;
fvertek = y;
