0

我有一个 3D 矩阵Atn x n x nvarnvar变量y1...y25。我很容易将变量输入 cvx:

cvx_begin sdp;
    variable A(2*nbus,2*nbus) symmetric;
    variable y(1,nvar);
    maximize sum(y*Mfun);
    A ==  subs(At,yt,y(1,nvar));

但是,最后一行的相等性给了我这个错误:

Error using sym/subs>normalize (line 197)
Substitution expression X must be a symbolic, cell, or numeric array.
Error in sym/subs>mupadsubs (line 137)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok
Error in sym/subs (line 125)
    G = mupadsubs(F,X,Y);

我试图用几种不同的方式来建立这种平等:

使用我最初创建的相同for循环At(使用Cfun双精度矩阵):

A == for k = 1:nvar
    At = At + yt(k)*Cfun(:,:,k);
end

这给出了这个错误:

Error: File: proj.m Line: 124 Column: 11
Illegal use of reserved keyword "for".

我真的没想到它会起作用,但认为它值得一试。

我也尝试使用bsxfun在 cvx 中创建矩阵,但我不相信 bsxfun 能够处理符号。repmat是我现在正在研究的“bsxfun”(有人告诉我)的替代品。

The reason I am trying to do the problem in this way is to create a routine that can use cvx to solve an optimal power flow for any number/combination of buses, without have to create variable individually each time.

4

1 回答 1

0

After posting I spent 30 more minutes on it and figured it out. Rather than writing the for loop inside the equality constraint, I wrote it cvx_begin after the variable declaration:

cvx_begin sdp;
    variable A(2*nbus,2*nbus) symmetric;
    variable y(1,nVar);
    maximize sum(y*Mfun);
    for k = 1:nVar
        At = At + y(k)*Cfun(:,:,k);
    end
    for k = 1:size(cY,3)
        At = At + cY(:,:,k);
    end
    A ==  At;
    for k = 1:nIneq
        y(k)>=0;
    end
    A>=0;
cvx_end;
于 2016-05-04T07:14:07.737 回答