function main() % Dane x0 = 1; % Początkowe przybliżenie eps = 1e-8; % Precyzja % Wywołanie funkcji do znajdowania miejsca zerowego result = find_zero(@func_to_solve, x0, eps); fprintf('Miejsce zerowe: %.8f\n', result); % Graficzne przedstawienie funkcji i miejsca zerowego x_vals = linspace(result - 2, result + 2, 1000); y_vals = func_to_solve(x_vals); figure; plot(x_vals, y_vals, 'LineWidth', 2); hold on; plot(result, 0, 'ro', 'MarkerSize', 10, 'MarkerFaceColor', 'r'); title('Funkcja f(x) = 2^x - 4x i miejsce zerowe'); xlabel('x'); ylabel('f(x)'); grid on; legend('f(x)', 'Miejsce zerowe', 'Location', 'Best'); end function y = func_to_solve(x) y = 2^x - 4 * x; end function result = find_zero(func, x0, eps) x = x0; k = 0; while true y = g(x); z = g(y); delta = ((y - x)^2) / z - 2 * y + x; x_new = x - delta; if abs(delta) <= eps result = x_new; break; end x = x_new; k = k + 1; end end function y = g(x) y = func_to_solve(x); end