How to implement inequality constrainst in fmincon

1 view (last 30 days)
Hi, I need to implement inequality constraint for fmincon. The constraint is Z < d where d is constant and Z is function https://www.mathworks.com/matlabcentral/answers/388799-how-to-implement-inequality-constrainst-in-fmincon#imageof optimization variable x. Z is given as max(W*f(x)), here f(x) is linear and given f(x) = mx+c and W is a constant matrix. I have written following code for this function but do not know how to adapt it for fmincon. Secondly, is there a way to invert this function so that it can be written as bound constraint instead of inequality. Any help would be appreciated.
d = 3;
W = [1, 0.5, 0.25; 0, 1, 0.5; 0, 0, 1];
x = rand(3,3);
fx = 0.7*x + 0.5;
P = W*fx;
Z = max(P);
Z = Z - d;

Answers (1)

vijaya lakshmi
vijaya lakshmi on 19 Mar 2018
Hi Saifullah Khalid ,
In order to adapt the inequality constraint in fmincon, you can take advantage of the additional input parameter to “fmincon” called ‘nonlcon’.
The purpose of ‘nonlcon’ is to allow you to implement a function that takes in the vector input and add constraints to an output array.
For further information about ‘nonlcon’, please see the Input Arguments > nonlcon section in the following documentation: fmincon
To add the additional constraints to "fmincon", create an additional function that will be used to specify constraints. Add this function handle to the call to "fmincon"
Refer to the below example to understand its usage:
fmincon(@(m0)myfunc(m0, other_params), m0, [], [], [], [], LB, UB) ; %fmincon
Where m0 is the initial estimate for m.
fmincon(@(m0)myfunc(m0, other_params), m0, [], [], [], [], LB, UB, @constrainM) %fmincon with function handle added
function [c, ceq] = constrainM(m0) % inequality constraint function

Categories

Find more on Optimization 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!