# f newton iteraltjai [a,b]-n x0 kezdeti becslesbol, N iteracio
function newton(f,df,a,b,x0,N)

% egy abrara rajzolunk
hold on;

% fuggveny, es tengely
x = a : 0.01 : b;
plot(x, f(x), 'b');
grid on;

% newton iteraciok
xn = x0;
for i = 1 : N
    
    % xn kiirasa
    disp(xn);
    
    % fuggvenyertek xn-ben
    fxn = f(xn);
    
    % derivalt xn-ben
    dfxn = df(xn);
    
    % x tengely -> fgv fuggoleges vonal
    line([xn, xn], [0, fxn], "color", 'g');
    
    % fgv -> x tengely erinto 
    line([xn, xn - fxn ./ dfxn], [fxn, 0], "color", 'k');
    
    % uj iteracio
    xn = xn - fxn ./ dfxn; 
end

hold off;

endfunction