Help !! Problems Using fmincon

1 次查看(过去 30 天)
Ahmad Sawwas
Ahmad Sawwas 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

回答(1 个)

Erivelton Gualter
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]
% Create your a array
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
Matt J 2019-11-21
编辑: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
Erivelton Gualter 2019-11-21
Thanks Matt ;)
I have been doing unnecessary work.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by