# Help !! Problems Using fmincon

3 ビュー (過去 30 日間)
Ahmad Sawwas 2019 年 11 月 21 日
コメント済み: Erivelton Gualter 2019 年 11 月 21 日
Hello Everyone,
i am trying to use fmincon to find an optimal matrix which minimizes a cost function.
Assuming the matrix is called "x", x being an (N x T) matrix, (where N and T are known values) has the following form:
x = [ x11 x12 x13 ........ x1T
x21 x22 x23 ........ x2T
.... .... ....
. ....
. ....
. ....
. ....
xN1 xN2 xN3 .......... XNT ]
The problem that im facing is that i have linear equality constraints and linear inequality constraints, for example:
the sum of x(:,1) = a1;
the sum of x(:,2) = a2;
.
.
the sum of x(:,T) = aT;
and the inequality constraints are:
the sum of x(1,:) <= b1;
the sum of x(2,:) <= b2;
.
.
the sum if x(N,:) <= bN;
how can i formulate such constraints using fmincon ??
Thanks

#### 3 件のコメント

Walter Roberson 2019 年 11 月 21 日
I suggest you look at Problem Based Optimization.
Ahmad Sawwas 2019 年 11 月 21 日
Sorry but i didnt understand your advice, what do you mean by problem based optimization ?
Walter Roberson 2019 年 11 月 21 日

サインイン to comment.

### 回答 (1 件)

Erivelton Gualter 2019 年 11 月 21 日
I see that you already have choose your solver, which is fmincon. Go over on the Description of the solver and note it contains Linear Inequality and Equality Constraint. There are the A,b, Aeq, and beq variables.
I assume that you may be confused only on formualting the constraints and you know how to code cost function and apply fmincon.
Note, fmincon will minimize x, which is an array. So, you need to reshape the matrix arguments in 1D representation. For example:
% If you have 3x3
x=[x11, x21, x31;
x12, x22, x32;
x13, x23, x33]
x = [x11, x21, x31, x12, x22, x32, x13, x23, x33]
% Select A, b, Aeq and beq
A = eye(3)
b = [a1 a1 a1 a2 a2 a2 a3 a3 a3];
Aeq = eye(3)
b = [b1 b1 b1 b2 b2 b2 b3 b3 b3];
Hopefully it gave you some insignt.

#### 2 件のコメント

Matt J 2019 年 11 月 21 日
Note, fmincon will minimize x, which is an array. So, you need to reshape the matrix arguments in 1D representation.
No, fmincon will do the reshaping for you automatically. However, the A, Aeq have to be constructed with the expectation that they will be multiplied with x(:)
A*x(:)<=b(:)
Aeq*x(:)=beq;
Erivelton Gualter 2019 年 11 月 21 日
Thanks Matt ;)
I have been doing unnecessary work.

サインイン to comment.

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

Translated by