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
-blahSquares=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!
Best Answer