# Unable to use lagrange to solve 2 varable functions in modeling toolkit

**URL:** <https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043>\
**Category:** Optimization (Mathematical)\
**Created:** [November 25, 2021, 5:47am UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043 "2021-11-25T05:47:13Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 26, 2021, 9:34pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/22 "2021-11-26T21:34:34Z")

</div>

I took this stuff, but I don’t remember much of it. T means the transvers of a matrix? How do i create a Hessian matrix from quadratic equations?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 27, 2021, 8:19pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/23 "2021-11-27T20:19:04Z")

</div>

What about GalacticOptim?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 27, 2021, 8:40pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/24 "2021-11-27T20:40:01Z")

</div>

Is JuMP insufficient for your needs? It sounded like you already have something working.

If you have a limited background in linear algebra and nonlinear optimization in general, I’d suggest you stick with JuMP.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 27, 2021, 9:15pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/25 "2021-11-27T21:15:08Z")

</div>

The matrices was suggested, and I was currious about GalacticOptim, but I think i will use JuMP mostly.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [November 27, 2021, 9:17pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/26 "2021-11-27T21:17:20Z")

</div>

The name Q usually suggests an orthogonal matrix (real-valued) or unitary matrix (same idea for complex matrices. Key property is Q^TQ = I (for real-valued orthogonal Q), or Q^\* Q = I (for complex-valued, unitary Q).

Is that the term you’re looking for? Orthogonal/unitary matrices are kind of “unit” matrix, in that they don’t scale vectors, just rotate them. Kind of like a complex constant c with unit magnitude.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 27, 2021, 9:18pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/27 "2021-11-27T21:18:21Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [November 28, 2021, 10:45pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/28 "2021-11-28T22:45:15Z")

</div>

Just a quick comment on that: solving the associated linear system is equivalent if the QP is convex and you only have equality constraints. This seems to be the case here 👍

Solving a general QP (with inequalities and possibly nonconvex objective) is much more difficult (NP-hard if nonconvex).

---

<div class="post-metadata">

**Author:** ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)\
**Post date:** [November 29, 2021, 9:34am UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/29 "2021-11-29T09:34:17Z")

</div>

Well, strictly speaking, in this particular case the unconstrained problem (the function to be maximized) is nonconvex (the eigvals of Q are -1 and 1). It is only after imposing the equality constraints that the problem turns into a convex one. This is checked by computing the reduced/projected Hessian, which turns out negative.

I double checked and this is aligned with the exposition in the dedicated section 16.1 in Nocedal’s popular bible of optimization.

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [November 29, 2021, 10:58am UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/30 "2021-11-29T10:58:07Z")

</div>

Yep, you’re absolutely right: the reduced Hessian (= the Hessian projected on the nullspace of the active constraints) should be positive (resp. negative) definite in the case of minimization (resp. maximization). In your case the problem is concave, which is the favorable case when you maximize.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 29, 2021, 2:12pm UTC](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043/31 "2021-11-29T14:12:33Z")

</div>

I’m only interested in the positive quadrant.

[Previous page](https://discourse.julialang.org/t/unable-to-use-lagrange-to-solve-2-varable-functions-in-modeling-toolkit/72043.md?page=1)
