How to specify Multiple constraints for LSQLIN (Part 2)

Previously I had asked and MattJ successfully answered the following scenario : I have X = 50 data points for 6 parameters, resulting in output vector Y of 50 data points. I have first constrained the problem so that the Y predicted values are > 0 by setting A = -X, b = 0*Y, and solved via BETA = lsqlin(X,Y,A,b) . I now want to specify multiple constraints so BETA(1)*X(1) + BETA(2)*X(2) is always > 0 , BETA(3)*X(3) + BETA(4)*X(4) > 0 , and BETA(5)*X(5) + BETA(6)*X(6) > 0 for all 50 predicted values. Can someone help me with this? Thanks.
Matt's solution was : tmp={X(:,1:2),X(:,3:4),X(:,5:6)}; A=-[X;blkdiag(tmp{:})]; b=zeros(size(A,1),1); lsqlin(X,Y,A,b)
I now need to add another constarint to the original constraints, that the ratio [BETA(1)*X(1) + BETA(2)*X(2)] / [BETA(3)*X(3) + BETA(4)*X(4)] must be between -0.7 and 0.7 Thanks.

 Accepted Answer

Matt J
Matt J on 24 Jun 2013
Edited: Matt J on 24 Jun 2013
The new constraints are equivalent to
BETA(1)*X(1) + BETA(2)*X(2) + 0.7*[BETA(3)*X(3) + BETA(4)*X(4)] <=0
and
BETA(1)*X(1) + BETA(2)*X(2) - 0.7*[BETA(3)*X(3) + BETA(4)*X(4)] <=0
These are just additional linear constraints and can be appended to the already existing ones.

7 Comments

I don't see how to take these inequalities and add them to the "tmp" variable. I still need to define A and b with dimensions that allow the lsqlin command of lsqlin(X,Y,A,b)
Matt J
Matt J on 25 Jun 2013
Edited: Matt J on 25 Jun 2013
tmp will not play a role here. You will create a 2nd A and b whose rows specify your new constraints. Then you will append them (vertically) to the old A and b.
Sorry, still not getting it, can you specify the exact steps?
So, suppose A1,b1 are the constraint matrices that you have already computed so far (based on our conversation in your earlier thread). Now you have new constraint matrices A2, b2 as we have discussed above. The rows of A2,b2 specify the new constraints
BETA(1)*X(1) + BETA(2)*X(2) + 0.7*[BETA(3)*X(3) + BETA(4)*X(4)] <=0
and
BETA(1)*X(1) + BETA(2)*X(2) - 0.7*[BETA(3)*X(3) + BETA(4)*X(4)] <=0
So now you just combine them to get total constraint matrices
A=[A1;A2];
b=[b1;b2];
and now you feed this A,b pair to LSQLIN. And that's it!
But how do I specify A2 and b2?
Was in a little rush yesterday, working now, thanks again, I owe you one!
ok. glad it's working!

Sign in to comment.

More Answers (0)

Products

Asked:

on 24 Jun 2013

Community Treasure Hunt

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

Start Hunting!