# Matlab optimization help

• Jul 21st 2010, 06:20 AM
Maric
Matlab optimization help
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!!
• Jul 21st 2010, 07:31 PM
CaptainBlack
Which function are you using to do the minimisation, and which algorithm have you set it to use?

CB
• Jul 22nd 2010, 04:36 AM
Maric
I am using fmincon and active set, but I also tried with interior point and it is the same. Thanks!
• Jul 22nd 2010, 06:47 AM
CaptainBlack
Quote:

Originally Posted by Maric
I am using fmincon and active set, but I also tried with interior point and it is the same. Thanks!

Try 'sqp'

CB
• Jul 22nd 2010, 02:23 PM
Maric
Thanks, but I understand that Active set is sqp. I only have three options: Active set, interior point and trust region reflective. Btw, I am using matlab 2009.
• Jul 22nd 2010, 02:33 PM
CaptainBlack
Quote:

Originally Posted by Maric
Thanks, but I understand that Active set is sqp. I only have three options: Active set, interior point and trust region reflective. Btw, I am using matlab 2009.

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:

Quote:

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.
(explains why I never use it, I usually use Nelder-Mead with penalty functions to implement (soft) constraints, or stochastic search of some kind)

CB
• Jul 22nd 2010, 02:40 PM
CaptainBlack
Quote:

Originally Posted by Maric
Thanks, but I understand that Active set is sqp. I only have three options: Active set, interior point and trust region reflective. Btw, I am using matlab 2009.

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:

Quote:

Active-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.

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.