Skip to content

Instantly share code, notes, and snippets.

@silgon
Created May 22, 2023 14:29
Show Gist options
  • Save silgon/103a0e8c168ccc4f206e8dfe4768ad53 to your computer and use it in GitHub Desktop.
Save silgon/103a0e8c168ccc4f206e8dfe4768ad53 to your computer and use it in GitHub Desktop.
import numpy as np
import cvxpy as cp
α = 0.3
A = np.array([[1., α], [α, 1.5]])
# maximum eigenvalue
t = cp.Variable()
prob = cp.Problem(cp.Minimize(t), [np.eye(2)*t-A>>0])
prob.solve()
# minimum eigenvalue
t = cp.Variable()
prob = cp.Problem(cp.Minimize(-t), [A-np.eye(2)*t>>0])
prob.solve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment