Which function are you using to do the minimisation, and which algorithm have you set it to use?
CB
Hello, I need some help with a matlab optimization problem. It is a constrained nonlinear optimization one and it only shows the first iteration, in which there are not Nan or Inf values for the objective function.
I am thinking it may be because I call a different function inside the objective function, but I am not sure if is a problem or not (I haven't find anything about it).
The code is very simple. It is the following:
function[der]=dercorte(a);
[g1,q]=otra(a)
r=q;
der=-abs(((a(1)-g1)*(a(6)-a(7))*a(5)*g1/((a(5)-1)*(1-q*(a(1)-g1*(1-q)))^2)));
And the function otra is:
function[g1,q]=otra(a);
g1=0.9;
dif=10;
while dif>0.001
q = -(-(a(6) * a(5) * a(1)) + (a(6) * a(5) * g1) + (a(5) * a(7) * a(1)) - (a(5) * a(7) * g1) - (a(6) * a(5)) - (a(6) * g1) - a(8) + a(6) + (a(8) * g1) + (a(8) * a(5)) + sqrt((4 * a(6) * a(5) ^ 2 * a(1) * a(7) * g1 - 2 * a(6) * a(5) * a(1) * a(8) * g1 - 2 * a(5) * a(7) * a(1) * a(6) * g1 + 2 * a(5) * a(7) * a(1) * a(8) * g1 + a(6) ^ 2 * a(5) ^ 2 * a(1) ^ 2 - 2 * a(6) ^ 2 * a(5) ^ 2 * a(1) + 2 * a(6) ^ 2 * a(5) * a(1) + a(6) ^ 2 * a(5) ^ 2 * g1 ^ 2 + 2 * a(6) ^ 2 * a(5) ^ 2 * g1 - 2 * a(6) ^ 2 * a(5) * g1 ^ 2 + a(5) ^ 2 * a(7) ^ 2 * a(1) ^ 2 + a(5) ^ 2 * a(7) ^ 2 * g1 ^ 2 + 4 * a(6) * a(5) * a(8) - 2 * a(6) * a(5) ^ 2 * a(8) + 4 * a(6) * g1 * a(8) - 2 * a(6) * g1 ^ 2 * a(8) + 2 * a(8) ^ 2 * g1 * a(5) - 2 * a(6) ^ 2 * a(5) ^ 2 * a(1) * g1 - 2 * a(6) * a(5) ^ 2 * a(1) ^ 2 * a(7) + 2 * a(6) ^ 2 * a(5) * a(1) * g1 - 2 * a(6) * a(5) * a(1) * a(8) + 2 * a(6) * a(5) ^ 2 * a(1) * a(8) - 2 * a(6) * a(5) ^ 2 * g1 ^ 2 * a(7) - 2 * a(6) * a(5) * g1 * a(8) + 2 * a(6) * a(5) * g1 ^ 2 * a(8) - 2 * a(6) * a(5) ^ 2 * g1 * a(8) - 2 * a(5) ^ 2 * a(7) ^ 2 * a(1) * g1 + 2 * a(5) ^ 2 * a(7) * a(1) * a(6) + 2 * a(5) * a(7) * a(1) * a(8) - 2 * a(5) * a(7) * a(1) * a(6) - 2 * a(5) ^ 2 * a(7) * a(1) * a(8) - 2 * a(5) ^ 2 * a(7) * g1 * a(6) + 2 * a(5) * a(7) * g1 ^ 2 * a(6) - 2 * a(5) * a(7) * g1 * a(8) + 2 * a(5) * a(7) * g1 * a(6) - 2 * a(5) * a(7) * g1 ^ 2 * a(8) + 2 * a(5) ^ 2 * a(7) * g1 * a(8) + a(6) ^ 2 * a(5) ^ 2 - 2 * a(6) ^ 2 * a(5) + a(6) ^ 2 * g1 ^ 2 - 2 * a(6) ^ 2 * g1 + a(8) ^ 2 - 2 * a(8) * a(6) - 2 * a(8) ^ 2 * g1 - 2 * a(8) ^ 2 * a(5) + a(6) ^ 2 + a(8) ^ 2 * g1 ^ 2 + a(8) ^ 2 * a(5) ^ 2))) / (a(5) - 1) / (a(6) - a(8)) / (a(1) - g1) / 0.2e1;
gn=min((((a(2)-a(7))*a(5)-(a(2)-a(6)))/a(3))*a(4)*(1-q),1);
dif=sqrt((g1-gn)^2);
g1=gn;
end
Can anybody help me please? Thanks!!
I was worried by what follows when I first saw your objective but ignored it while doing some background research, your objective does not obviously have continuous derivatives (it may have if the "corners" and other pathologies do not occur during the search), and we have the following from the help system:
(explains why I never use it, I usually use Nelder-Mead with penalty functions to implement (soft) constraints, or stochastic search of some kind)Limitations
fmincon is a gradient-based method that is designed to work on problems where the objective and constraint functions are both continuous and have continuous first derivatives.
CB
The documentation suggests that sqp is able to recover from nan and inf, presumably there is a difference in how Active set abd sqp are implemented as otherwise they would not both be options:
You probably don't need it but the online help page is hereActive-Set Optimization
fmincon uses a sequential quadratic programming (SQP) method. In this method, the function solves a quadratic programming (QP) subproblem at each iteration. fmincon updates an estimate of the Hessian of the Lagrangian at each iteration using the BFGS formula (see fminunc and references [7] and [8]).
fmincon performs a line search using a merit function similar to that proposed by [6], [7], and [8]. The QP subproblem is solved using an active set strategy similar to that described in [5]. fmincon Active Set Algorithm describes this algorithm in detail.
See also SQP Implementation for more details on the algorithm used.
Interior-Point Optimization
This algorithm is described in fmincon Interior Point Algorithm. There is more extensive description in [1], [41], and [9].
SQP Optimization
fmincon uses a sequential quadratic programming (SQP) method. In this method, the function solves a quadratic programming (QP) subproblem at each iteration. fmincon updates an estimate of the Hessian of the Lagrangian at each iteration using the BFGS formula (see fminunc and references [7] and [8]).
fmincon performs a line search using a merit function similar to that proposed by [6], [7], and [8]. The QP subproblem is solved using an active set strategy similar to that described in [5]. fmincon Active Set Algorithm describes this algorithm in detail.
See also SQP Implementation for more details on the algorithm used.
CB
Thanks, but I think my version is different. I do not have sqp as a different option, my version's help says that active set uses sqp. I will try to update.
Regarding continuity, derivatives are continuous in all points but one; maybe I have to try more initial conditions.
Thank you!