Fmincon active-set solver
Show older comments
Hello everyone,
I have a problem regarding one of the solvers of fmincon.
This is the example from the matlab documentation for solving a constrained optimiziation problem:
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
A = [];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
nonlcon = @unitdisk;
x0 = [0,0];
options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
function [c,ceq] = unitdisk(x)
c = x(1)^2 + x(2)^2 - 1;
ceq = [];
end
And I get the following:
Iter Func-count Fval Feasibility Step Length Norm of First-order
step optimality
0 3 1.000000e+00 0.000e+00 1.000e+00 0.000e+00 2.000e+00
1 12 8.913011e-01 0.000e+00 1.176e-01 2.353e-01 1.107e+01
2 22 8.047847e-01 0.000e+00 8.235e-02 1.900e-01 1.330e+01
3 28 4.197517e-01 0.000e+00 3.430e-01 1.217e-01 6.172e+00
4 31 2.733703e-01 0.000e+00 1.000e+00 5.254e-02 5.705e-01
5 34 2.397111e-01 0.000e+00 1.000e+00 7.498e-02 3.164e+00
6 37 2.036002e-01 0.000e+00 1.000e+00 5.960e-02 3.106e+00
7 40 1.164353e-01 0.000e+00 1.000e+00 1.459e-01 1.059e+00
8 43 1.161753e-01 0.000e+00 1.000e+00 1.754e-01 7.383e+00
9 46 5.901601e-02 0.000e+00 1.000e+00 1.547e-02 7.278e-01
10 49 4.533081e-02 2.898e-03 1.000e+00 5.393e-02 1.252e-01
11 52 4.567454e-02 2.225e-06 1.000e+00 1.492e-03 1.679e-03
12 55 4.567481e-02 4.406e-12 1.000e+00 2.095e-06 1.501e-05
13 58 4.567481e-02 0.000e+00 1.000e+00 2.159e-09 1.511e-05
If I change the code to:
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
A = [];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
nonlcon = @unitdisk;
x0 = [0,0];
options = optimoptions('fmincon','Display','iter','Algorithm','active-set');
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
function [c,ceq] = unitdisk(x)
c = x(1)^2 + x(2)^2 - 1;
ceq = [];
end
And I get the following:
Not enough input arguments.
f = fval;
nlconst(funfcn,X,l,u,full(A),B,full(Aeq),Beq,confcn,options,defaultopt, ...
So my question is, what I am doing wrong?
1 Comment
Hi Sven,
I understand that you are encountering an error when changing the solver for the “fmincon” function. I have executed both code snippets you provided in MATLAB R2020a, and I did not encounter the same error. The 'active-set' algorithm worked as expected and found a solution to the optimization problem.
Please confirm the version of MATLAB you are using, as the behavior of “fmincon” and its algorithms can differ between versions. If you are using a version older than R2020a, there may be differences that could explain the error.
If your MATLAB installation is not up to date, I recommend updating it to the latest service pack or patch. This could resolve unexpected behavior due to software bugs. Additionally, double-check that the code you are running is identical to the code snippet provided and that there are no typos or alterations.
Hope this helps!
Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!