Help !! Problems Using fmincon

2 views (last 30 days)
Ahmad Sawwas
Ahmad Sawwas on 21 Nov 2019
Commented: Erivelton Gualter on 21 Nov 2019
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 Comments
Ahmad Sawwas
Ahmad Sawwas on 21 Nov 2019
Sorry but i didnt understand your advice, what do you mean by problem based optimization ?

Sign in to comment.

Answers (1)

Erivelton Gualter
Erivelton Gualter on 21 Nov 2019
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 Comments
Matt J
Matt J on 21 Nov 2019
Edited: Matt J on 21 Nov 2019
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 on 21 Nov 2019
Thanks Matt ;)
I have been doing unnecessary work.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!