33 lines
1014 B
Plaintext

% Given environment
clear;
% Setup the function under test
syms x [2 1] real;
fexpr = (1/3)*x(1)^2 +3*x(2)^2;
title_fun = "$f(x) = frac{1}{3}{x_1}^2 + 3{x_2}^2$";
% Calculate the gradient and Hessian
grad_fexpr = gradient(fexpr, x); % Gradient of f
hessian_fexpr = hessian(fexpr, x); % Hessian of f
% Convert symbolic expressions to MATLAB functions
fun = matlabFunction(fexpr, 'Vars', {x}); % Function
grad_fun = matlabFunction(grad_fexpr, 'Vars', {x}); % Gradient
hessian_fun = matlabFunction(hessian_fexpr, 'Vars', {x}); % Hessian
% Minimum reference
%Freference = @(x) x(1).^5 .* exp(-x(1).^2 - x(2).^2);
%[Xmin, Fmin] = fminsearch(Freference, [-1, -1]);
% Amijo globals
global amijo_beta; % Step reduction factor in [0.1, 0.5] (typical range: [0.1, 0.8])
global amijo_sigma; % Sufficient decrease constant in [1e-5, 0.1] (typical range: [0.01, 0.3])
%fixed step size globals
global gamma_fixed_step
global image_width,
global image_height;
image_width = 960;
image_height = 640;