# Nearest complex positive semidefinite matrix

**URL:** <https://discourse.julialang.org/t/nearest-complex-positive-semidefinite-matrix/23228>\
**Category:** General Usage\
**Created:** [April 17, 2019, 1:20am UTC](https://discourse.julialang.org/t/nearest-complex-positive-semidefinite-matrix/23228 "2019-04-17T01:20:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)\
**Post date:** [April 17, 2019, 1:20am UTC](https://discourse.julialang.org/t/nearest-complex-positive-semidefinite-matrix/23228/1 "2019-04-17T01:20:05Z")

</div>

There seem to be [a lot of work](https://nickhigham.wordpress.com/2013/02/13/the-nearest-correlation-matrix/) on finding the nearest positive semidefinite matrix to a real symmetric matrix, but other than via an eigendecomposition, which is slow (as below), does anyone know of a way to find the nearest PSD matrix to a _complex Hermitian_ matrix?

```julia
function project_psd(H)
    # take the eigendecomposition, set any negative
    # eigenvalues to 0, and reconstruct
    D,V = eigen(Hermitian(H))
    D .= max.(D,0)
    return Hermitian(V*Diagonal(D)*V')
end

```

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [April 17, 2019, 6:11am UTC](https://discourse.julialang.org/t/nearest-complex-positive-semidefinite-matrix/23228/2 "2019-04-17T06:11:25Z")

</div>

Try formulating your problem as a conic program and use a conic solver, e.g. [GitHub - mariohsouto/ProxSDP.jl: Semidefinite programming optimization solver](https://github.com/mariohsouto/ProxSDP.jl). Also if you ask in the optimization category, you may find more helpful comments from the SDP folks there.

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [April 17, 2019, 7:29am UTC](https://discourse.julialang.org/t/nearest-complex-positive-semidefinite-matrix/23228/3 "2019-04-17T07:29:20Z")

</div>

I don’t know much about this type of problems, but often methods that work or symmetric matrices work for hermitian as well, by changing transposes to adjoints and adding a few `real()`.
