larg number constraints in matlab

조회 수: 2 (최근 30일)
mohammad azimipary
mohammad azimipary 2021년 9월 13일
댓글: mohammad azimipary 2021년 9월 15일
I have an optimization problem which have a larger number of variables,N=20;
how i can define this constrain? please answer to me
Qe and Qi is a matrix (40*10)
Z=[I2g,I2h, W]';
W=sdpvar(1,2*N+2);
function [cineq,ceq]=nonlcon(Z)
N=20;
for(n=1:N)
cineq(1*n)= Qe(n,:)*PP*Z-W(1)*ones(N,1)<= -10000; %%for all N indicates a vector inequality
cineq(2*n)= -Qe(n,:)*PP*Z+W(2)*ones(N,1)<= 10000; %%for all N indicates a vector inequality
cineq(3*n)= Qi(n,:)*ZZ+500-W(3+n)<=0;
cineq(4*n)= -W(3+n)<=0;
cineq(5*n)= W(N+3+n)-Qi(n,:)*ZZ-500<=0;
cineq(6*n)= W(N+3+n)<=0; %%for all N indicates a vector inequality
cineq(7*n)=sum(W(3:N+2))-sum(W(N+3:2*N+2))<=N*Iavemax;
cineq(8*n)=500+Qi(n,:)*ZZ<=Imax*ones(N,1);
cineq(9*n)=-Imax*ones(N,1)<=500+Qi(n,:)*ZZ;
end
ceq=[];
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 14일
Maybe?
sdpvar() is from the third-party package YALMIP https://yalmip.github.io so whether it works or not depends upon YALMIP not on MATLAB.
The [cineq,ceq] style like that is for nonlinear constraints defined by MATLAB. I am not aware that YALMIP has any facility to call nonlinear constraints using that style.
The individual elements you assign look plausible to me to be YALMIP constraint declarations on their right-hand side.
The locations you assign to on the left are broken. Consider than when n = 1, the fourth cineq(4*n) would be assigning to cineq(4*1) = cineq(4) . But when n = 2, the second cineq(2*n) would be assigning to cineq(2*2) = cineq(4) which would overwrite the previous entry. And you never write to any location with a prime index greater than 9. cineq(13) is never assigned to, for example.
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 9월 14일
You have to move
const=sum(cineq);
SS=optimize(const,obj);
z=value(Z);
to before the function statement.
Also, that sum(cineq) will have to be changed to sum(sum(cineq)) or sum(cineq(:))
mohammad azimipary
mohammad azimipary 2021년 9월 15일
thank you , but doesn't work . beacuse 'cineq' must be define before difine 'const=sum(cineq(:))'.
and when i do that give me previous Error.

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

추가 답변 (1개)

Johan Löfberg
Johan Löfberg 2021년 9월 14일
편집: Walter Roberson 2021년 9월 14일
You're better off posting YALMIP specific questions on YALMIP specific forums

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by