Error using barrier Objective function is undefined at initial point. Fmincon cannot continue.
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Can anyone see why I get this error:
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 895)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in untitled4 (line 19)
[x_opt, f_opt, exitflag] = fmincon(augmented_objective, x0, [], [], [], [], [], [], [], options);
When running this code:
main_function = @(x) (2*x(1) + x(2))^2 + x(2)^4 - 4*x(1) - 4*x(2);
constraints = @(x) [x(1)^2 + x(2)^2 - 4; -(4*x(1) + 5*x(2) - 4)];
max_it = 5;
x0 = [10; 10]; % Initial guess
Beta = 0.1; % Initial penalty parameter
% Increase max iterations due to initial guess
options = optimoptions('fmincon', 'Display', 'iter', 'MaxIterations', 1000);
for it = 1:max_it
% Define the barrier function
barrier_function = @(x) -sum(log(constraints(x) + 1e-6));
% Define the augmented objective function with the barrier term
augmented_objective = @(x) main_function(x) + (1/Beta) * barrier_function(x);
augmented_objective(x0)
% Using fmincon to minimize the problem
[x_opt, f_opt, exitflag] = fmincon(augmented_objective, x0, [], [], [], [], [], [], [], options);
% Check if the optimization converged successfully
if exitflag <= 0
fprintf('Optimization did not converge at iteration %d.\n', it);
break;
end
% Update the initial guess for the next iteration
x0 = x_opt;
Beta = Beta * 10;
fprintf('Iteration %d: x_opt = [%.4f, %.4f], f_opt = %.4f\n', it, x_opt, f_opt);
end
0 commentaires
Réponses (1)
Torsten
le 14 Sep 2023
Déplacé(e) : Torsten
le 14 Sep 2023
If you insert the line
augmented_objective(x0)
before the call to fmincon, you will see that your objective returns a complex number. This is forbidden in optimization problems.
The reason is that your constraint function takes "log" of a negative number.
Voir également
Catégories
En savoir plus sur Matched Filter and Ambiguity Function dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!