Implicit Constraints using fmincon

Hello,
I have the following otpimzation problem: The objective function is given by: f(x)=x_1+...+x_n+x_{n+1}+...x_{n+d} And the constraints are given by: -x_i-x_j- sqrt(x_{n+1}+...+x_{n+d}) for 1<=i<j<=n. My question is how i can define the matrix of constraints A using fmincon.
Can someone help me to do this? Thanks in advance.

 采纳的回答

Torsten
Torsten 2015-10-15
Use the nonlinear constraint c(x)<=0 instead of the linear constraint A*x<=b.
Best wishes
Torsten.

3 个评论

Thanks for ur answer. in fact i define my objective function as:
function f = objfun(r)
S=0;
n=3;
dimension=2;
for i=1:n
S=S+r(i);
end
for d=1:dimension
S=S+r(n+d);
end
f=S;
and the constraints as:
function [c, ceq] = confun(r)
% Nonlinear inequality constraints
n=4;
c=zeros(n*(n-1)/2,1);
for i=1:n
for j=i+1:n
c(i)=r(i)+r(j)-1;
end
end
% Nonlinear equality constraints
ceq = [];
and i got this error:
Attempted to access r(3); index out of bounds because numel(r)=2.
Do you have any idea?
Thanks again.
You seem to have a solution vector with two elements, but you address r(3),r(4) and r(5) in the two routines from above - elements which do not exist.
Best wishes
Torsten.
Thank you so much

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by