how to write series of multiple non-linear constraints for optimization using fmincon in MATLAB?

Hi, I have serios of multiple non-linear constraints and i am stuck how to write them in MATLAB, please help me out how to write the overall sum for n values. I have attached the problem below.
constraints.png
e.g. if phi and tau are the optimal variables which are x(1) and x (2) and the value of beta = 5,
Rn is the sumrate of main code and Rn' is the sumrate threshold value (10*1000) ,
function [c,ceq]=constraints(x)
c(1)=?
c(2)=?
c(3)=?
c(4)=sumrate(x)-10*1000
ceq=[];
end
how to erite the other constraints?
thank you in advance

3 Kommentare

From what you write, your constraints and your objective are linear.
Thus use "linsolve" instead of "fmincon" for a solution.
Hi sir, here is my objective function
obj.png
shall i use linsolve instead of fmincon?
how it can be linear beacuse i have Prn equal to this.
power.png

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

xi
xi am 17 Sep. 2019
Bearbeitet: xi am 17 Sep. 2019
You have 2n parameters, named X1,X2...Xn(for phi) and Xn+1...X2n (for tau).
You need to write the constraints in the vectorized format of Ax-b<0, where A is a matrix, b is a vector. The #rows of A as well as the length of b is determined by how many contraints you have, and the #columns is 2n (number of parameters).
In your case, the first three sets of constraints are linear constraints (total of 1+1+2n=2n+2). Your A matrix should have 2n+2 rows:
A(1,:)= [ones(1,n),zeros(1,n)];
A(2,:)= [zeros(1,n),ones(1,n)];
A=[A;-eye(2*n)];
b=[(1-beta);beta;zeros(2*n,1)]

10 Kommentare

Except that you should use lb, and ub arguments for simple bounds, so
A = [ones(1,n),zeros(1,n);...
zeros(1,n),ones(1,n)];
b=[(1-beta);beta];
Aeq=[],beq=[];
lb=zeros(2*n,1);
ub=[];
Thank you Sir for your response, but i want to confirm that as my 1st three constraints are linear and the last one is non-linear so shall i use the above method you mentioned or make a separate function file for all the constraints??
xi
xi am 18 Sep. 2019
Bearbeitet: xi am 18 Sep. 2019
Matt is right, using lb, ub is much simpler, should have thought about that.
Maheen: The first three are linear constraints, and the last one is nonlinear, so still need to write a constraint function for the last item, and in combination with the linear parameter settings mentioned above.
Your non-linear constraint function looks like this: (there are n of them)
function [c,ceq]=myconstraint(x)
n=length(x)/2;
for i=1:n
c(i) = sumrate(x(i), x(i+n)) -10*1000
end
ceq = [];
end
Sir, i just want to know that how to write the over all sum <= 1-beta in the constraints?
e.g. if value of beta =0.4,
and i have 6 phi values to optimize, i have to optimize its value but the sum of all these 6 phi values not exceed 1-beta (i.e 0.6).
constraintt.png
i will be thank full to you, if you could answer this question.
Matt is right, using lb, ub is much simpler, should have thought about that.
It is not just that it is simpler to input. It is the only way fmincon can distinguish between complicated linear constraints and simple bounds constraints. If fmincon sees that you have simple bounds, it will handle those in a special, more efficient way.
Maheen Fazal,
Matt J already has the answer, the first constraint is written as:
1*x1+1*x2+...1*x6 - (1-beta)<=0
write it in vectorized format of A*X-b<=0;
where, A=(1,1,1,1,1,1); X=(x1;x2;x3;x4;x5;x6); b=1-beta;
because you have another six parameters(tau: defined as x7 to x12). A and X should be revised as
A(1,:)=(1,1,1,1,1,1,0,0,0,0,0,0); X=(x1;x2....X12); b(1)=1-beta;
The same for the second constraint, where
A(2,:)=(0,0,0,0,0,0,1,1,1,1,1,1); X=(x1;x2....X12); b(2)=beta;
Hope this is clear to you now
Hi Sir, by applying the above method i am facing some problems kindly help me to resolve it.
after executing the codes, MATLAB is giving me the following errors,Sir can you tell me why is it so??
  • Subscripted assignment dimension mismatch.
  • Error in mycode (line 27)
  • A(1,:)=[ones(1,n),zeros(1,n)]
Is it the right way to write the constraints for 2-parameters??
A=[ones(1,n),zeros(1,n);zeros(1,n),ones(1,n)]
b=[(1-B);B;];
instead of this??
A(1,:)= [ones(1,n),zeros(1,n)];
A(2,:)= [zeros(1,n),ones(1,n)];
A=[A;-eye(2*n)];
b=[(1-beta);beta;zeros(2*n,1)]
I don't see anything wrong. Just use the compact version. The way I wrote separately for A(1,:) and A(2,:) is just to help explain. Note that, 2 rows mean 2-constraint equations, not 2-parameters. It should also work unless A was already defined and you are likely to get the dimension mismatch error,
Yes you are right, i have two parameters and for both parameters there are two separate equations.
constraintss.png
so for that i wrote linear inequality constraints like this as mentioned below, but still not getting the proper graph.
A=[ones(1,n),zeros(1,n);zeros(1,n),ones(1,n)]
b=[(1-B);B;];

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

am 13 Sep. 2019

Kommentiert:

am 4 Okt. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by