5

How do I invert a matrix of variables in cvxpy?

I have a matrix of problem variables defined as follows:

import cvxpy as cp
A = cp.Variable(2,2)

and I want to solve a program with an objective function involving the inverse of this matrix. I have tried almost every method I could possibly think of (including manually defining the inverse matrix), but nothing seems to work.

The full code for my problem is:

A = cp.Variable((2,2)) # matrix A is 2X2
c = cp.Variable(2) # center of 2d ellipsoid

constraints = [A >> 0]
constraints += [cp.pnorm(cp.matmul(A, v[i] - cp.matmul(A,c)), p=2) <= np.array([1,1]) for i in range(10)]

# this is where I'm stuck. Using np.linalg.inv doesn't work.
# I also can't seem to calculate this inverse manually 
obj_fn = cp.log_det(np.linalg.inv(A))

prob = cp.Problem(cp.Minimize(obj_fn), constraints)
prob.solve(solver='CVXOPT')
DLim
  • 93
  • 5

1 Answers1

4

I don't know how to invert a matrix in cvxpy, but for the specific code you have, you can use the fact that:

log det A^{-1} = - log det A

cfulton
  • 2,855
  • 2
  • 14
  • 13