フィルターのクリア

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 Center および File ExchangeMathematics and Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by