Untitled
% Funzione per il Metodo della Secante function [root, iter] = metodo_secante(f, x0, x1, tol, max_iter) iter = 0 while iter < max_iter fx0 = f(x0) fx1 = f(x1) %Formula x_new = x1 - fx1*(x1-x0)/(fx1-fx0); if abs(x_new - x1) < tol root = x_new; return; end x0=x1; x1 = x_new; iter = iter + 1; end root = x_new; end f = @(x) exp(x) -10*x; x0 = 2; x1 = -2; tol = 1e-6; max_iter = 100; [root, iter] = metodo_secante(f, x0, x1, tol, max_iter); fprintf('Radice trovata: %.6f in %d iterazioni\n', root, iter);
Leave a Comment