function x = newton(f, g, x_0, tol, tol_0) if (tol > 0.0001 * tol_0) drawtol = tol; else drawtol = 0.0001 * tol_0; end x_plot = x_0-tol_0:drawtol:x_0+tol_0; plot(x_plot, f(x_plot)); hold on; % plot([x_0-tol_0, x_0+tol_0], [x_0-tol_0, x_0+tol_0]); % plot(x_plot, f(x_plot)); if (g(x_0) ~= 0) x = fpi_err(@(x) x-f(x)./g(x), x_0, tol, tol_0); else x = fpi_err(@(x) x-f(x)./(f(x+0.5)-f(x-0.5)), x_0, tol, tol_0); end