필터 지우기
필터 지우기

Is fmincon ignoring my non-linear constraint?

조회 수: 4 (최근 30일)
kschau
kschau 2013년 4월 17일
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
Matt J
Matt J 2013년 4월 17일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2013년 4월 17일
편집: Matt J 2013년 4월 17일
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
kschau
kschau 2013년 4월 17일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by