how to write this constraint in fmincon

1 view (last 30 days)
Hi, does any one know how to write this constraint in fmincon?
sum(abs(x- w0) ) <= 0.3
w0 is known and it is a Nx1 vevctor. x is the unkown.
Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Feb 2020
abs() can only be handled as a nonlinear constraint
function [c, ceq] = nonl(x, w0)n
c = sum(abs(x-w0)) - 0.3;
ceq = [];
And the corresponding location in the fmincon parameter list would be
@(x) nonl(x, w0)

More Answers (1)

Matt J
Matt J on 28 Feb 2020
Edited: Matt J on 28 Feb 2020
Because the constraint is non-smooth, you cannot use fmincon's nonlinear constraint support to implement this. Instead you have to use a more indirect method, which reformulates the problem in terms of two unknown vectors x and y. If your original problem is,
then the reformulated problem is as below (which requires only linear constraints).
  3 Comments
Matt J
Matt J on 3 Mar 2020
Edited: Matt J on 3 Mar 2020
That's why I recommended that you don't do it! But I guess you got it to work somehow, since you ended up accepting Walter's answer?
Lingjuan Ma
Lingjuan Ma on 4 Mar 2020
Hi Matt, I have other constraints and Walter's answer coincided with what I had initially. But then I realised, from your answer, why sometimes it did not work. Thanks again.

Sign in to comment.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!