I want to minimize the following minimization problem using fmincon
in MATLAB
The code below (Strategy 1) that I have written solves the problem when I replace the logarithmic (nonlinear) constraint by the linear constraint sum(x) = 5
. So how can I change it to introduce the logarithmic constraint? I am blocked here.
MATLAB CODE (Strategy 1):
x0 = zeros(3,1);
Sigma = rand(3,3); %take any matrix
Obj_func = @(x) sqrt(x' * Sigma * x);
options = optimoptions('fmincon','Algorithm','interior-point', 'MaxFunctionEvaluations', 1e100);
[x, FVAL, EXITFLAG, OUTPUT] = fmincon(Obj_func, x0, [], [], ones(1,3), 5, zeros(3,1), inf(3,1), [], options);
Another way to do it (see This reference) can be as below but I am sure if I am correct. (I need help).
MATLAB CODE (Strategy 2):
fun = @(x)sqrt(x' * Sigma * x);
nonlcon = @my_function;
x0 = [0 0 0]';
A = []; % No other constraints
b = [];
Aeq = [];
beq = [];
lb = zeros(3,1);
ub = inf(3,1);
w = fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon)
function [const,ceq] = my_function(x)
const(1) = 5 - sum(log(x));
ceq = [];
end
Any help will be very appreciated!