Borrar filtros
Borrar filtros

Is fmincon ignoring my non-linear constraint?

4 visualizaciones (últimos 30 días)
kschau
kschau el 17 de Abr. de 2013
Hey there!
I am using matlab's fmincon function to perform what is essentially a least squared curve fit subjected to non linear constraints. The basic layout of the procedure is this:
The coefficients "guessed" (we'll call them Betas) Beta1, Beta2, and Beta3 are subject to the equality:
Beta1+Beta2+Beta3=1
With these coefficients "guessed", a scaling factor (alpha) must be calculated, where:
alpha=0.786*Beta1+0.3231*Beta2+0.1191*Beta3
The constants above are static constants, nothing more.
With these values (Betas and alpha), an array is generated at various values of my argument, and compared in a least squared sense to my "goal" array I am trying to match.
What is happening is, for negative values of alpha, my generated array can contain imaginary, NaN, or Inf; which does not agree at all with fmincon. So I added the additional non-linear inequality:
alpha >= 0
However, this does not prevent my alpha from being negative! I left of the ';' at the end of my alpha calculation and it still comes up negative in my command window right before fmincon is terminated. Not sure what is going on.
Here is my call function:
Betas=[1 0 0]; %initial guess
[Betas]=fmincon(@FINDTERMS,Betas,[],[],[],[],lb,ub,@myconst); %call fmincon
function [Squares] = FINDTERMS(Betas) %function used to generate "guessed" array
constants=[0.746 0.3231 0.1191];
alpha=dot(Betas,constants(1:length(Betas)))
-blah
-blah %based on betas and alpha, generate the GuessedLine array
-blah
Squares=sum((GuessedLine-RealLine).^2);
end
function [c, ceq] = myconst(Betas)%constraints for what Betas can and cannot be
constants=[0.7468 0.3231 0.1191];
c=-dot(Betas,constants(1:length(Betas))); %This should prevent alpha from being negative, right?
ceq=sum(Betas)-1;
end
Again, for my 'FINDTERMS' function, I am leaving off the ';' at the end of the alpha calculation, which should never be negative based on my 'c' constraint in @myconst.
Any help is greatly appreciated!
  1 comentario
Matt J
Matt J el 17 de Abr. de 2013
It doesn't really make sense for you to be using myconst for this purpose. All of the constraint formulas in myconst are linear functions of Beta, so you should be using A,b,Aeq,beq to describe these constraints.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 17 de Abr. de 2013
Editada: Matt J el 17 de Abr. de 2013
Yes, all FMINCON algorithms only satisfy nonlinear constraints asymptotically, not at every iteration.
Try using the interior point or sqp algorithm options. They can recover from NaNs and Infs.
Also, you should specify alpha>=0 using linear (in)equality constraints, as mentioned in my Comment above, although I don't know how much value this contraint would really add anyway. alpha=0 is still a legitimate value and I imagine that would still give you NaN or Inf, even if successfully enforced.
  1 comentario
kschau
kschau el 17 de Abr. de 2013
Ahhhh I see, thank you. And you are correct about the linearity of my constraints, not exactly sure what I was thinking with this. Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics and Optimization en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by