"Too many input Argument" error in optimize a matrix w

Uncategorized
Mar 20, 2018
R

I have the code to find matrix w optimal:

"prompt = 'How many relays N do you want? ';
n = input(prompt) %numbers of relay N
snrthreshdb=10;
snrthesh=10^(snrthreshdb/10);
phi2=1; %0db
Psdb=14;%14db
Ps=10^(Psdb/10);
In=eye(n,n)%Identity matrix nxn
fRn=zeros(1,n)
gRn=zeros(1,n);
hRn=zeros(1,n);
cEn=zeros(1,n);
phifc=zeros(1,n);
phigc=zeros(1,n);
phifh=zeros(1,n);

for count=1:n
fRn(1,count)=normrnd(0,1)+normrnd(0,1)*i %row vector
gRn(1,count)=normrnd(0,1)+normrnd(0,1)*i %row vector
hRn(1,count)=normrnd(0,1)+normrnd(0,1)*i %row vector
cEn(1,count)=normrnd(0,1)+normrnd(0,1)*i %row vector
phifc(1,count)=fRn(1,count)*cEn(1,count);
phigc(1,count)=gRn(1,count)*cEn(1,count);
phifh(1,count)=fRn(1,count)*hRn(1,count)
end

Rff=diag(fRn);
Rgg=diag(gRn);
Rhh=diag(hRn);
Rfh=phifh*ctranspose(phifh);

for Psum=10:5:40
PRi=Psum/(n+1);
Pn=Psum/(n+1);
Q=Ps * Rff+Pn * Rgg+phi2*In

cvx_begin
    variable w(n,n) complex       
    minimize (w')*Q*w %.............................................................error position
    (Ps*(w')*Rfh*w)/(phi2*(1+(w')*Rhh*w))>=10;
    for count=1:n
      w(count,count)*(w(count,count)')*Q(1,1)<=PRi;
    end      
cvx_end

end"

After running the program, I received error message:
“Error using minimize
Too many output arguments.
Error in desRsvsPs (line 40)
minimize (w’)Qw”
Can someone help me solve the problem?

M

The error message is because the closing parenthesis is in the wrong place. It should be
minimize (w'*Q*w)

However, once you do that, you will encounter another, more serious, error. That is because your objective function evaluates to an n by n matrix. it needs to evaluate to a real scalar. Because I don’t know what you are trying to model, I can’t tell you how to fix it.

R
Replying to #2

This is first time I used cvx to simulate an article so I really don’t know how to make a cvx code from a formula.
I try to simulate formula in red box (the above are parts of formula in red box)

M

For starters, w should be a vector, not a matrix.

Then you have more work to do to get the problem into a form CVX can accept, if that is even possible (I leave that to you).

O
Replying to #2

Hi, Mark_L_Stone can you help me
My code is follow :

function [lame_eau, CemaParam] = CemaNeige( Pt, T, Tmax, Tmin, Date, CemaParam )

G = CemaParam.G;
eTg = CemaParam.eTg;
Zz = CemaParam.Zz;
ZmedBV = CemaParam.ZmedBV;
Beta = CemaParam.Beta;
gradT = CemaParam.gradT;
Tf = CemaParam.Tf;
QNBV = CemaParam.QNBV;
Vmin = CemaParam.Vmin;

CTg = CemaParam.CTg;
Kf = CemaParam.Kf;

[JJ] = JJdate (Date(1),Date(2),Date(3));
eday = zeros( 1,3 ) ;
eday(1) = JJ(1);
eday(2) = Date(1);

eday(3) = eomday(eday(2),2);
if eday(3) == 29
if JJ(1) > 59
JJ(1)=JJ(1)-1;
end
end

i = 1;

ind = JJ(1);
theta = gradT(i);

Tz = T + theta*(Zz - ZmedBV)./100;
Tzmax = Tmax+theta*(Zz-ZmedBV)./100;
Tzmin = Tmin+theta*(Zz-ZmedBV)./100;
Pdis = Pt/5;
modc = exp(Beta*(Zz-ZmedBV));
c = sum(modc)/5;
Pz = (1/c)*Pdis(1)exp(Beta(Zz-ZmedBV));

Fracneige = zeros(1,5);

for z = 1 : 5
if ZmedBV < 1500 % Fonction Hydrotel
if Tzmax(z) <= 0
Fracneige(z) = 1;
elseif Tzmin(z) >= 0
Fracneige(z) = 0;
else
Fracneige(z) = 1-(Tzmax(z)/(Tzmax(z)-Tzmin(z)));
end
else
if Tz(z) > 3
Fracneige(z) = 0;
elseif Tz(z) < -1
Fracneige(z) = 1;
else
Fracneige(z) = 1-((Tz(z)-(-1))/(3-(-1)));
end
end
end

Fracneige = min(Fracneige,1);
Fracneige = max(Fracneige,0);

Pg = Pz .* Fracneige;
Pl = Pz - Pg;

G = G + Pg;
eTg = CTg*eTg+(1-CTg)*Tz;
eTg = min(0,eTg);

fTg = (eTg >= Tf);

Fpot = (Tz > 0) .* (min(G,Kf*(Tz-Tf).*fTg));

Gseuil = QNBV*0.9;
fnts = min(G/Gseuil,1);

fonte = Fpot .* ((1-Vmin)*fnts+Vmin);

G = G - fonte;
lame_eau = sum(Pl) + sum(fonte);
CemaParam.G = G;
CemaParam.eTg = eTg;

end

function [JJ] = JJdate (A,M,J)
test = and(mod(A,4)==0,or(mod(A,100)~=0,mod(A,400)==0));
x = test+0;
JJ = floor(275*M/9)-(2-x).*floor((M+9)/12)+J-30;
end

function CemaParam = CemaNeigeInit( Zz, ZmedBV, Beta, gradT, x, Tf, QNBV, Vmin )
CemaParam.CTg = x(end-1);
CemaParam.Kf = x(end);

CemaParam.G = zeros( 1,5 ) ;
CemaParam.eTg = zeros( 1,5 ) ;

CemaParam.Zz = Zz;
CemaParam.ZmedBV = ZmedBV;
CemaParam.Beta = Beta;
CemaParam.gradT = gradT;
CemaParam.Tf = Tf;
CemaParam.QNBV = QNBV;
CemaParam.Vmin = Vmin;
end

and i have this error :

Error using CemaNeige
Too many input arguments

M

Your code does not appear to have any relation to CVX. Therefore, you are seeking support in the wrong place.