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일

0 개 추천

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

댓글 수: 3

Heborvi
Heborvi 2015년 10월 15일
편집: Heborvi 2015년 10월 15일
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.
Torsten
Torsten 2015년 10월 15일
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.
Heborvi
Heborvi 2015년 10월 15일
Thank you so much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2015년 10월 15일

댓글:

2015년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by