Computation time of iterative equation shorter than appropriate vectorized form!

Uncategorized
Mar 25, 2016
D

I"m using cvx with MATLAB and sdpt3 solver. The computation time of my optimization problem is with following iterative equation

for i=1:N
X(i+1) == X(i) - I(i) * C;
end

two times shorter, than with the vectorized equation:

X(1) == X0;
X(2:(N+1)) == X0 .* ones(1,N) - sum(repmat(I,N,1) .* tril(ones(N,N),0),2)’ .* C;

Outside the CVX enviroment the second equation is multiple times faster using MATLAB. Can somebody tell me what is happening in the background of CVX causing this?

M

I don’t really know exactly why one would be slower or faster than the other. But CVX itself isn’t designed for speed, rather for convenience. If you’ve found a case where for loops are faster, then by all means, you should take advantage of it!