﻿function x = modified_secant_method(g, x0, x1, tol, max_iter)
    fprintf('Iter \t xn \n');
    for iter = 1:max_iter
        g0 = feval(g, x0);
        g1 = feval(g, x1);
        
        a = (g1 - g0) / (x1 - x0);
        b = g0 - a * x0;
        
        x = -b / a;
        
        fprintf('%d \t %.8f \n', iter, x);
        
        if abs(x - x1) < tol
            fprintf('Converged to solution: %.8f\n', x);
            return;
        end
        
        x0 = x1;
        x1 = x;
    end
    fprintf('Did not converge within maximum iterations.\n');
end
