using Convex n = 20 p = 2 A = rand(n,p) + im*randn(n,p) x = rand(p) + im*randn(p) b = abs(A*x) + rand(n) M = diagm(b)*(eye(n)-A*ctranspose(A))*diagm(b) U = ComplexVariable(n,n) objective = inner_product(U,M) c1 = diag(U) == 1 c2 = U in :SDP p = minimize(objective,c1,c2) solve!(p) U.value # Verify if the rank of U is 1 B, C = eig(U.value); println(length([e for e in B if(abs(real(e))>1e-4)])) #Decompose U = uu* # u is the phase of Ax u = C[:,1]; for i in 1:n u[i] = u[i]/abs(u[i]) end u