涉及矩阵逆的JuMP约束 [英] JuMP constraints involving matrix inverse

查看:93
本文介绍了涉及矩阵逆的JuMP约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试求解n*n矩阵U,该矩阵满足各种约束,包括一些涉及其子矩阵逆的约束.但是,看来JuMP至少在没有其他一些可逆性规范的情况下无法处理逆.这是n=2问题的示例.

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)

这会引发以下错误:

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?

推荐答案

您不能在宏之外使用inv(或更普遍地说,构建任何非线性表达式).像这样把它放进去:

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.,因为我不知道unmixed_iv2是什么,所以我无法运行您的示例.

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

这篇关于涉及矩阵逆的JuMP约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆