# The solution of Semidefinite Programming (SDP) violates the constraints

**URL:** https://discourse.julialang.org/t/the-solution-of-semidefinite-programming-sdp-violates-the-constraints/63370
**Category:** Optimization (Mathematical)
**Created:** [June 22, 2021, 1:56pm UTC](https://discourse.julialang.org/t/the-solution-of-semidefinite-programming-sdp-violates-the-constraints/63370 "2021-06-22T13:56:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sawyer\_Zhou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sawyer_zhou/32/18745_2.png) [@Sawyer\_Zhou](https://discourse.julialang.org/u/Sawyer_Zhou)
#### Post date: [June 22, 2021, 1:56pm UTC](https://discourse.julialang.org/t/the-solution-of-semidefinite-programming-sdp-violates-the-constraints/63370/1 "2021-06-22T13:56:52Z")

</div>

I try to solve a SDP, the result shows that the solution is feasible and optimal, but when I substitute the obtained solution back into the constraints, I find it violates many constraints.

```julia
using JuMP, MosekTools, LinearAlgebra, Random
Random.seed!(20);
n = 3
Q = rand(-50:50,n,n)
c = rand(-50:50,n)
l = zeros(n)
u = ones(n)
SemiDP = Model(with_optimizer(Mosek.Optimizer))
@variable(SemiDP, X[1:n,1:n])
@variable(SemiDP, x[1:n])
@objective(SemiDP, Min, dot(Q,X)+c'*x)
@constraint(SemiDP, x*u'-X .>= 0) 
@constraint(SemiDP, X.>=0) 
@SDconstraint(SemiDP, [1 x'; x X]>=0)
optimize!(SemiDP)
println(primal_status(SemiDP))
println("termination_status:", termination_status(SemiDP))

```

It shows the solution is optimal and primal feasible, but when I substitute the solution into the constraints:

```julia
value.(x)*u'-value.(X) .>= 0
eigvals([1 value.(x)'; value.(x) value.(X)]) #to see if the matrix is Semidefinite

```

I find it violates many constraints, e.g. some bool values are 0, and some eigenvalues are negative. Could anybody give some ideas on how the problem comes?

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [June 22, 2021, 4:57pm UTC](https://discourse.julialang.org/t/the-solution-of-semidefinite-programming-sdp-violates-the-constraints/63370/2 "2021-06-22T16:57:39Z")

</div>

Here is what I get

```julia
julia> value.(x)*u'-value.(X)
3×3 Matrix{Float64}:
  4.63377e-10 -2.53719e-10 1.44575e-9
  3.61053e-10 -2.6613e-10 2.56338e-9
 -3.33895e-10 1.68968e-10 1.42857e-11

julia> eigvals([1 value.(x)'; value.(x) value.(X)])
4-element Vector{Float64}:
 -3.4264861390395915e-10
 -7.479956860042055e-11
  1.7273934867396232e-9
  3.999999996555678

```

The biggest violation for the first constraint is `-2.53719e-10` and the biggest for the second is `-3.4264861390395915e-10` which is within the tolerance so I don’t think there is any issue.

---

<div class="post-metadata">

### Author: ![Sawyer\_Zhou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sawyer_zhou/32/18745_2.png) [@Sawyer\_Zhou](https://discourse.julialang.org/u/Sawyer_Zhou)
#### Post date: [June 22, 2021, 7:17pm UTC](https://discourse.julialang.org/t/the-solution-of-semidefinite-programming-sdp-violates-the-constraints/63370/3 "2021-06-22T19:17:55Z")

</div>

Thanks for your reply, I missed the point you talk about.  
Thanks!
