# Modeling sum of k-smallest eigenvalues of a symmetric matrix in JuMP

**URL:** <https://discourse.julialang.org/t/modeling-sum-of-k-smallest-eigenvalues-of-a-symmetric-matrix-in-jump/63245>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [June 20, 2021, 5:07pm UTC](https://discourse.julialang.org/t/modeling-sum-of-k-smallest-eigenvalues-of-a-symmetric-matrix-in-jump/63245 "2021-06-20T17:07:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [June 20, 2021, 5:07pm UTC](https://discourse.julialang.org/t/modeling-sum-of-k-smallest-eigenvalues-of-a-symmetric-matrix-in-jump/63245/1 "2021-06-20T17:07:05Z")

</div>

Dear All,

I am trying to model the following convex constraint in `JuMP`:

\sum\_{i=1}^{k} \lambda\_i(X) \geq c,

where X \in \mathbf{S}^n (a symmetric matrix), c is a constant, and \lambda\_1(X) \leq \lambda\_2(X) \leq \ldots \leq \lambda\_n(X) for solving an optimization problem with X as the decision variable. The constraint represents that the sum of k smallest eigenvalues of the symmetric matrix X is greater than c.

Note that the constraint \sum\_{i=1}^{k} \lambda\_i(X) \geq c is a convex constraint, as the function \sum\_{i=1}^{k} \lambda\_i(X) is concave on X\in \mathbf{S}^n due to the [Raleigh-Ritz formula](https://people.math.gatech.edu/~ecroot/notes_linear.pdf) (also, see the [cvxpy link](https://www.cvxpy.org/tutorial/functions/index.html), where it is listed as a concave function).

Is there a way to model such a constraint in `JuMP`?

Any tips will be much appreciated!

---

<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 20, 2021, 7:36pm UTC](https://discourse.julialang.org/t/modeling-sum-of-k-smallest-eigenvalues-of-a-symmetric-matrix-in-jump/63245/2 "2021-06-20T19:36:30Z")

</div>

This is the same as `-sum` of the `k` largest eigenvalues of `X` for which a reformulation is given in p. 147 of “Lectures on modern convex optimization” of Ben-Tal and Nemirovski.  
So for the first `k` eigenvalues of `X`, you would do

```julia
using LinearAlgebra, JuMP
n = LinearAlgebra.checksquare(X) # Same as size(X, 1) but also check that it is square
@variable(model, Z[1:n, 1:n], Symmetric)
@variable(model, s)
@constraint(model, Symmetric(Z - X + s * Matrix(I, n, n)) >= 0)

```

Then `k * s + tr(Z)` is constrained to be an upper bound to the sum of the largest `k` eigenvalues. So if it’s minimized, it will be equal to it.  
And if this is minimized or

---

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [June 20, 2021, 7:59pm UTC](https://discourse.julialang.org/t/modeling-sum-of-k-smallest-eigenvalues-of-a-symmetric-matrix-in-jump/63245/3 "2021-06-20T19:59:15Z")

</div>

This is a great solution, thanks so much @blegat !
