N = 25;
yalmip('clear')
B=sdpvar(N,N,'full')
tic
Bsq=B^2;
toc
yalmip('clear')
B=sdpvar(N^2,1,'full')
tic
Bsq=reshape(B.^2,N,N);
toc
Linear matrix variable 25x25 (full, real, 625 variables)
Elapsed time is 25.044241 seconds.
Linear matrix variable 625x1 (full, real, 625 variables)
Elapsed time is 0.030131 seconds.
N = 1e5;
x =sdpvar(N,1);
R = sprandn(N,N,0.01);Q=R'*R;
obj = x'*Q*x; %Slooooow
con = [-1 <= x <= 1]
z = sdpvar(N,1);
obj = z'*z; % Fast
con = [z == R*x, -1 <= x <= 1]; % No problems for good solvers
B=sdpvar(N^2,1,'full')
Bsq=reshape(B,N,N)^2
then there does not appear to be any computation time advantage vs. the first method
B=sdpvar(N,N,'full')
Bsq=B^2;
Which of us has the misunderstanding?function varargout = stone(varargin)
switch class(varargin{1})
case 'double'
B = varargin{1};
B = reshape(B,sqrt(length(B)),[]);
C = varargin{2};
varargout{1} = trace(C*B*B');
case 'sdpvar'
varargout{1} = yalmip('define',mfilename,varargin{1:2});
case 'char'
B = varargin{3};
C = varargin{4};
operator = struct('convexity','none','monotonicity','none','definiteness','none','model','callback');
operator.derivative = @(x) derivative(x,C);
varargout{1} = [];
varargout{2} = operator;
varargout{3} = B;
otherwise
error('What?');
end
function d = derivative(B,C)
B = reshape(B,sqrt(length(B)),[]);
d = C*B+B*C;
d = d(:);
X = sdpvar(3,3,'full');
C = randn(3);C = C*C';
Y = randn(3);
solvesdp([],trace(C*(X-Y)*(X-Y)'));
double(X)
ans =
-0.1269 0.1098 -1.9673
1.0703 0.0481 -0.6273
0.7669 -0.6433 1.3464
solvesdp([],stone(X-Y,C),sdpsettings('solver','ipopt'));
double(X)
ans =
-0.1269 0.1098 -1.9673
1.0703 0.0481 -0.6273
0.7669 -0.6433 1.3464
sdpvar k
Var1=V...
[V,D] = eig(W_original);
x1=V*diag(diag(D).^k)*V'*y1;
x2=V*diag(diag(D).^k)*V'*y2;
Objective = ((x1(2)-x2(2)).^2)./(Var1);
solvesdp([10 >= k>=1e-3],Objective,sdpsettings('solver','bmibnb'))
solvesdp([10 >= k>=1e-3,Objective>=0],Objective,sdpsettings('solver','bmibnb','usex0',1))
solvesdp([10 >= k>=1e-3,cut(Objective>=0)],Objective,sdpsettings('solver','bmibnb','usex0',1))