# Linear Constraint based on two variables fmincon

1 ビュー (過去 30 日間)
stickynote156 2019 年 11 月 12 日
Answered: John D'Errico 2019 年 11 月 12 日
Hello,
I am attempting to set a linear constraint on a multivarible optimization of fmincon. I am trying to figure out how to based this constraint on two other parameters.
For example.. I have parameters a,b, and c
I need to say that a < b/2 - c/2
However, I do not mean to say that a is between c/2 and b/2
I mean to say that a is between 0 and (b/2 - c/2 )
Any ideas on how to write this with fmincon linear inequality constraints? I previously and mistakenly had written it like this, and was preventing the a variable from getting lower which is more optimum
A(3,4) = 1;
A(3,2) = -1/2;
A(3,5) = 1/2;
b(3) = 0;
Thanks

#### 1 件のコメント

stickynote156 2019 年 11 月 12 日
I also should note, a, b, and c in this case are all variables up for optimization

サインイン to comment.

### 件の回答 (1)

John D'Errico 2019 年 11 月 12 日
Why, if you already have other inequality constraints, is this a question? And how you wrote it, using A is inconsistent with you having only 3 variables. So, clearly you have more variables in your real problem, and you even already have more than one linear inequality constraint!
If you had only one constraint, and you had only 3 variables, in the order b, a, and c, you would write:
A = [-1/2, 1, 1/2];
b = 0;
But, assuming this is the THIRD linear inequality constraint, AND that the variables concerned are variables 4, 2, and 5 in the set, you would do this:
A(3,[2 4 5]) = [-1/2, 1, 1/2];
b(3) = 0;
Note that no matter what you do, you cannot enforce a STRICT inequality with < as opposed to <=. Thus you can only set a constraint as:
a - b/2 + c/2 <= 0
and even that is only enforced to within a constraint tolerance.

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

Translated by