# \[JuMP\] Sectionwise definition of matrix with @expression

**URL:** <https://discourse.julialang.org/t/jump-sectionwise-definition-of-matrix-with-expression/15639>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 28, 2018, 7:21pm UTC](https://discourse.julialang.org/t/jump-sectionwise-definition-of-matrix-with-expression/15639 "2018-09-28T19:21:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![korpuskel](https://avatars.discourse-cdn.com/v4/letter/k/b38774/32.png) [@korpuskel](https://discourse.julialang.org/u/korpuskel)\
**Post date:** [September 28, 2018, 7:21pm UTC](https://discourse.julialang.org/t/jump-sectionwise-definition-of-matrix-with-expression/15639/1 "2018-09-28T19:21:52Z")

</div>

I need to define an expression/variable that resembles a matrix. This matrix is defined sectionwise, so I tried:

@expression(m, O[b=1:n, i=1:n, j=1:n], 0)  
@expression(m, O[b=1:n, i=n+1, j=1:n], 0.5_T\_i[b][j])  
 @expression(m, O[b=1:n, i=1:n, j=n+1], 0.5_T\_i[b][i])  
@expression(m, O[b=1:n, i=n+1, j=n+1], v[b] - buses[b].v\_max - s)  
for b in bus\_set  
@SDconstraint(m, M[b,:,:] \>= 0)  
@SDconstraint(m, M[b,:,:] - O[b,:,:] \>=0)  
end

hoping that JuMP would recognize that, for example, O[b=1:n, i=1:n, j=1:n] and O[b=1:n, i=n+1, j=1:n] are part of the same expression. It turns out, that the expression is always overwritten by the last line. I was so far not able to figure out a way to properly define a matrix that can be used in constraints like that. Doing a naive concatenation of the form

for b in 1:n\_buses  
O[b,:,:] = [O1[b,:,:] O2[b,:,:]; O3[b,:,:] O4[b,:,:]]  
end

didn’t help either.

I’d highly appreciate any advice!  
Thanks,  
Robert
