CCCPaste

Scilab, newton function

function [x, k] = newton(foncjac, tol, N, x0)
    dx = 0;
    x = x0;
    [F0,J0] = foncjac(x0)
    nF0 = norm(F0)
    
    for k = 1:N
        [F , J] = foncjac(x)
        h = -J \ F;
        x = x + h;
        dx = norm(F) / nF0;
        if dx < tol then
            return [x, k];
        end
    end
    
    error("Pas de convergence en N itérations.")

endfunction