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
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}