Untitled
unknown
plain_text
a year ago
1.7 kB
2
Indexable
Never
% Tolga ENGİN, 20014507 % Newton-Raphson yöntemi function [x, iterations] = newtonRaphson(f, x0, tolerance, max_iterations) x = x0; iterations = 0; while iterations < max_iterations % Hesaplamaları yapın f_value = f(x); f_derivative = diff(f); f_derivative_value = f_derivative(x); x_new = x - f_value / f_derivative_value; % Hata kontrolü if abs(x_new - x) < tolerance x = x_new; return; end x = x_new; iterations = iterations + 1; end end % Secant (Kiriş) yöntemi function [x, iterations] = secantMethod(f, x0, x1, tolerance, max_iterations) x = x1; x_prev = x0; iterations = 0; while iterations < max_iterations % Hesaplamaları yapın f_value0 = f(x0); f_value1 = f(x1); x_new = x1 - f_value1 * (x1 - x0) / (f_value1 - f_value0); % Hata kontrolü if abs(x_new - x1) < tolerance x = x_new; return; end x0 = x1; x1 = x_new; iterations = iterations + 1; end end % Steffensen metodu function [x, iterations] = steffensenMethod(f, x0, tolerance, max_iterations) x = x0; iterations = 0; while iterations < max_iterations % Hesaplamaları yapın f_value = f(x); f_value_forward = f(x + f_value); delta_x = f_value / (f_value_forward - f_value); x_new = x - delta_x; % Hata kontrolü if abs(delta_x) < tolerance x = x_new; return; end x = x_new; iterations = iterations + 1; end end