CCCPaste

Newton Raphson

function x = newtonRaphson(x0, n)
    
    if g(x0) == 0
        error('The function has derivative  zero at x0')
    end

    x = x0;

    for i = 1 : n

        if g(x) == 0
            break;
        end

        x = x - (f(x) / g(x));
    end
end