# Cannot multiply a quadratic expression by an affine expression

**URL:** <https://discourse.julialang.org/t/cannot-multiply-a-quadratic-expression-by-an-affine-expression/101240>\
**Category:** Optimization (Mathematical)\
**Created:** [July 6, 2023, 4:21am UTC](https://discourse.julialang.org/t/cannot-multiply-a-quadratic-expression-by-an-affine-expression/101240 "2023-07-06T04:21:54Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [July 7, 2023, 2:05am UTC](https://discourse.julialang.org/t/cannot-multiply-a-quadratic-expression-by-an-affine-expression/101240/4 "2023-07-07T02:05:16Z")

</div>

> Does that mean I can’t define matrix product at all?

Correct. In the current version of JuMP, you cannot create expressions like `X * Y * Z` where `X`, `Y` and `Z` are arrays of JuMP variables.

One work-around is:

```julia
using JuMP, LinearAlgebra
n = 5
model = Model()
@variable(model, R[1:n, 1:n], Symmetric)
@variable(model, Q[1:n, 1:n], Symmetric)
@variable(model, RQ[1:n, 1:n], Symmetric)
@constraint(model, RQ .== R * Q)
@expression(model, P, Q' * QR)

```

This limitation is fixed in the work-in-progress nonlinear rewrite: [https://github.com/jump-dev/JuMP.jl/pull/3106](https://github.com/jump-dev/JuMP.jl/pull/3106).

---

_[View the full topic](https://discourse.julialang.org/t/cannot-multiply-a-quadratic-expression-by-an-affine-expression/101240)._
