Help !! Problems Using fmincon
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(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]
% 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.
Check this other answer. It may be helpful: https://www.mathworks.com/matlabcentral/answers/42691-minimizing-the-values-in-an-underdetermined-matrix-minimize-with-constraints
2 个评论
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;
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!