我有一个 3D 矩阵At
、n x n x nvar
和nvar
变量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.