The data for example is taken from MATPOWER website. MATPOWER is Matlab package for solving power flow and optimal power flow problems.

In [2]:
using Convex
using FactCheck
using MAT   #Pkg.add("MAT")
TOL = 1e-2;
input = matopen("Data.mat")
varnames = names(input)
Data = read(input, "inj","Y");

n=size(Data[2],1);
Y=Data[2];
inj=Data[1];
W = ComplexVariable(n,n);
objective = real(sum(diag(W)));
c1 = Constraint[];
for i=2:n
    push!(c1,sum(W[i,:].*(Y[i,:]'))==inj[i]);
end
c2 = W in :SDP
c3 = real(W[1,1])==1.06^2;
push!(c1, c2)
push!(c1, c3)
p = maximize(objective,c1);
solve!(p)
p.optval
#15.125857662600703
evaluate(objective)
#15.1258578588357


output = matopen("Res.mat")
names(output)
outputData = read(output, "Wres");
Wres = outputData
real_diff = real(W.value) - real(Wres);
imag_diff = imag(W.value) - imag(Wres);
@fact real_diff => roughly(zeros(n,n), TOL)
@fact imag_diff => roughly(zeros(n,n), TOL)

real_diff = real(W.value) - (real(W.value))';
imag_sum = imag(W.value) + (imag(W.value))';
@fact real_diff => roughly(zeros(n,n), TOL)
@fact imag_sum => roughly(zeros(n,n), TOL)
----------------------------------------------------------------------------
	SCS v1.1.8 - Splitting Conic Solver
	(c) Brendan O'Donoghue, Stanford University, 2012-2015
----------------------------------------------------------------------------
Lin-sys: sparse-direct, nnz in A = 1344
eps = 1.00e-04, alpha = 1.80, max_iters = 20000, normalize = 1, scale = 5.00
Variables n = 393, constraints m = 812
Cones:	primal zero / dual free vars: 406
	sd vars: 406, sd blks: 1
Setup time: 5.66e-04s
----------------------------------------------------------------------------
 Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
     0|      inf       inf      -nan      -inf       inf       inf  2.20e-03 
   100| 3.92e-02  8.28e-02  6.88e-05 -1.43e+01 -1.43e+01  1.09e-16  6.97e-02 
   200| 7.31e-03  1.97e-02  1.66e-05 -1.48e+01 -1.48e+01  3.94e-17  1.63e-01 
   300| 2.71e-03  5.88e-03  5.13e-06 -1.50e+01 -1.50e+01  6.17e-17  2.39e-01 
   400| 8.98e-04  1.92e-03  1.68e-06 -1.51e+01 -1.51e+01  9.01e-17  3.09e-01 
   500| 2.88e-04  6.27e-04  5.46e-07 -1.51e+01 -1.51e+01  1.13e-16  3.89e-01 
   600| 9.25e-05  2.02e-04  1.75e-07 -1.51e+01 -1.51e+01  8.97e-17  4.58e-01 
   680| 3.73e-05  8.15e-05  6.99e-08 -1.51e+01 -1.51e+01  1.14e-16  5.18e-01 
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 5.18e-01s
	Lin-sys: nnz in L factor: 2906, avg solve time: 2.80e-05s
	Cones: avg projection time: 7.15e-04s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 1.6632e-09, dist(y, K*) = 3.3345e-09, s'y/m = 5.6326e-11
|Ax + s - b|_2 / (1 + |b|_2) = 3.7318e-05
|A'y + c|_2 / (1 + |c|_2) = 8.1454e-05
|c'x + b'y| / (1 + |c'x| + |b'y|) = 6.9907e-08
----------------------------------------------------------------------------
c'x = -15.1259, -b'y = -15.1259
============================================================================
Out[2]:
Success :: (line:380) :: fact was true
  Expression: imag_sum --> roughly(zeros(n,n),TOL)
    Expected: [0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]
    Occurred: [1.47324e-8 2.1028e-8 4.76118e-9 1.56033e-9 2.16189e-8 -2.07994e-9 -3.28781e-9 3.99815e-9 -1.33103e-8 -5.16207e-9 1.90604e-9 4.77498e-9 5.49637e-10 3.16484e-9; 2.1028e-8 -5.8605e-8 3.1737e-8 3.14802e-8 2.75396e-8 -2.83886e-9 -3.90489e-9 3.36547e-9 -1.39231e-8 -5.79509e-9 1.07542e-9 3.96731e-9 -1.448e-10 2.34341e-9; 4.76118e-9 3.1737e-8 -1.43922e-7 4.70254e-8 1.81582e-9 -7.04992e-9 -7.77973e-9 -6.01772e-10 -1.78195e-8 -9.78469e-9 -3.06303e-9 -1.00137e-10 -4.23639e-9 -1.60775e-9; 1.56033e-9 3.14802e-8 4.70254e-8 -6.26428e-7 1.85397e-7 -9.78674e-9 9.66492e-8 -3.61871e-9 3.16696e-8 -1.2855e-8 -5.9648e-9 -3.42632e-9 -7.45081e-9 -4.59564e-9; 2.16189e-8 2.75396e-8 1.81582e-9 1.85397e-7 -3.68364e-7 7.83056e-8 -5.92887e-9 1.21506e-9 -1.60193e-8 -8.01166e-9 -7.45651e-10 1.74727e-9 -2.26153e-9 3.03972e-10; -2.07994e-9 -2.83886e-9 -7.04992e-9 -9.78674e-9 7.83056e-8 -7.73413e-7 -1.51512e-8 -7.84049e-9 -2.53699e-8 -1.67081e-8 1.20914e-7 8.97915e-8 1.80076e-7 -8.15528e-9; -3.28781e-9 -3.90489e-9 -7.77973e-9 9.66492e-8 -5.92887e-9 -1.51512e-8 -9.60216e-7 1.68287e-7 3.2363e-7 -1.73251e-8 -1.08051e-8 -8.24215e-9 -1.19812e-8 -9.19581e-9; 3.99815e-9 3.36547e-9 -6.01772e-10 -3.61871e-9 1.21506e-9 -7.84049e-9 1.68287e-7 -2.52616e-7 -1.84268e-8 -1.01616e-8 -3.30664e-9 -6.95602e-10 -5.06291e-9 -1.88775e-9; -1.33103e-8 -1.39231e-8 -1.78195e-8 3.16696e-8 -1.60193e-8 -2.53699e-8 3.2363e-7 -1.84268e-8 -1.54708e-6 3.93944e-7 -2.07369e-8 -1.82985e-8 -2.21247e-8 9.92939e-8; -5.16207e-9 -5.79509e-9 -9.78469e-9 -1.2855e-8 -8.01166e-9 -1.67081e-8 -1.73251e-8 -1.01616e-8 3.93944e-7 -9.50271e-7 1.57252e-7 -9.72903e-9 -1.37523e-8 -1.09643e-8; 1.90604e-9 1.07542e-9 -3.06303e-9 -5.9648e-9 -7.45651e-10 1.20914e-7 -1.08051e-8 -3.30664e-9 -2.07369e-8 1.57252e-7 -4.56091e-7 -2.18631e-9 -6.69014e-9 -4.30745e-9; 4.77498e-9 3.96731e-9 -1.00137e-10 -3.42632e-9 1.74727e-9 8.97915e-8 -8.24215e-9 -6.95602e-10 -1.82985e-8 -9.72903e-9 -2.18631e-9 -2.44064e-7 6.11229e-8 -1.13186e-9; 5.49637e-10 -1.448e-10 -4.23639e-9 -7.45081e-9 -2.26153e-9 1.80076e-7 -1.19812e-8 -5.06291e-9 -2.21247e-8 -1.37523e-8 -6.69014e-9 6.11229e-8 -5.3805e-7 8.08111e-8; 3.16484e-9 2.34341e-9 -1.60775e-9 -4.59564e-9 3.03972e-10 -8.15528e-9 -9.19581e-9 -1.88775e-9 9.92939e-8 -1.09643e-8 -4.30745e-9 -1.13186e-9 8.08111e-8 -3.22902e-7]