Is it possible to add more constraints than the default ones in LSQLIN function?

2 views (last 30 days)
I'm solving a constrained linear least-squares problem using lsqlin. I've specified values for C,d,A,b,Aeq and beq. I used all the default constraints that are included in the solver except for the uper and lower bounds.
Axb
Aeqx=beq
I want to add one more constraint to the solver that is different from the above constraints that I already used, Is there a way to specify more constraints in addition to the ones that are by default in the solver?
Any help is appreciated!
  3 Comments
HN
HN on 26 Jan 2023
Thanks for your reply @John D'Errico @Torsten. I have C as matrix of size 8x5. d is a column vector of size 8x1.
My first constraint is Axb where A is equal to C and b is a column vector equal to 0.9.*d.
The second constraint is Aeqx=beq where Aeq is matrix of 4x5 and beq is a column vector of zeros of size 4x1.
x will be obtained from the optimizer and it will be of size 5x1
After obtaining x from the optimizer, I'm calculating a new column d_new where d_new=C*x. It will have the same size as d.
I wanted to add an additional constraint in the optimizer that assures that each element in d_new has the same sign as its repective value in d.
Hope it's clearer!

Sign in to comment.

Accepted Answer

Matt J
Matt J on 26 Jan 2023
Edited: Matt J on 26 Jan 2023
You can still use lsqlin, but as John said, you can add additional inequality constraints as follows,
Q=-sign(d).*C;
r=zeros(size(d));
Aineq=[A;Q]
bineq=[b;r];
x = lsqlin(C,d,Aineq,bineq,Aeq,beq,lb,ub,x0,options)

More Answers (1)

Torsten
Torsten on 26 Jan 2023
Moved: Matt J on 26 Jan 2023
Use "fmincon" with the constraint (C*x).*d >=0 and define this constraint in function "nonlcon".

Community Treasure Hunt

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

Start Hunting!