필터 지우기
필터 지우기

How to implement inequality constrainst in fmincon

조회 수: 3 (최근 30일)
Saifullah Khalid
Saifullah Khalid 2018년 3월 16일
댓글: Saifullah Khalid 2018년 3월 19일
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;

답변 (1개)

vijaya lakshmi
vijaya lakshmi 2018년 3월 19일
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

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by