function [gamma] = gamma_armijo(f, grad_f, x0) % Calculates the best step based on amijo method % % f(xk​− γk*∇f(xk)) ≤ f(xk) − σ*γk*∥∇f(xk)∥^2 % % f: Objective function % x0: Initial (x,y) point % beta: beta factor in (0, 1) % signam: sigma factor in (0,1) global amijo_beta global amijo_sigma gamma = 1; % Start with a step size of 1 grad = grad_f(x0(1), x0(2)); % Perform Armijo line search while f(x0(1) - gamma * grad(1), x0(2) - gamma * grad(2)) > ... f(x0(1), x0(2)) - amijo_sigma * gamma * norm(grad)^2 gamma = amijo_beta * gamma; % Reduce step size end end