Chandler Squires
Chandler Squires

Reputation: 407

JuMP constraints involving matrix inverse

I'm attempting to solve for an n*n matrix U, which satisfies a variety of constraints, including some involving inverses of its sub-matrices. However, it seems that JuMP can't handle inverses, at least without some additional specification of invertibility. Here's an example of the problem with n=2.

using JuMP, Ipopt

m = Model(with_optimizer(Ipopt.Optimizer))
A = [5 7; 7 10]
B = [9 13; 13 19]
C = [3 4; 4 6]
nnodes = 2
@variable(m, U[1:nnodes, 1:nnodes])

A1 = U * A * U'
B1 = U * B * U'
C1 = U * C * U'

c1 = A1[1, 1] - 1
c2 = A1[2, 2] - 1
c3 = C1[1, 1] - 1
c4 = unmixed_iv2[1, 2]
a = A1[2, 2] - A1[2, 1] * inv(A1[1, 1]) * A1[2,1]  # Schur complement
b = B1[2, 2] - B1[2, 1] * inv(B1[1, 1]) * B1[2,1]  # Schur complement
c5 = a - b

@NLconstraint(m, c1 == 0)
@NLconstraint(m, c2 == 0)
@NLconstraint(m, c3 == 0)
@NLconstraint(m, c4 == 0)
@NLconstraint(m, c5 == 0)

solve(m)

This raises the following error:

ERROR: inv is not defined for type GenericQuadExpr. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.

Any suggestions on how to solve this problem?

Upvotes: 1

Views: 351

Answers (1)

Oscar Dowson
Oscar Dowson

Reputation: 2574

You cannot use inv outside the macros (or more generally, build up any nonlinear expression). Just put it inside like so:

using JuMP
model = Model()
@variable(model, x >= 0.5)
@NLconstraint(model, inv(x) <= 0.5)

p.s., I can't run your example because I don't know what unmixed_iv2 is.

Upvotes: 0

Related Questions