# Creating Matrix Parameters in JuMP

**URL:** <https://discourse.julialang.org/t/creating-matrix-parameters-in-jump/104159>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [September 22, 2023, 4:31pm UTC](https://discourse.julialang.org/t/creating-matrix-parameters-in-jump/104159 "2023-09-22T16:31:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Three](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@Three](https://discourse.julialang.org/u/Three)\
**Post date:** [September 22, 2023, 4:31pm UTC](https://discourse.julialang.org/t/creating-matrix-parameters-in-jump/104159/1 "2023-09-22T16:31:39Z")

</div>

Hello,

Sorry if this is a dumb question, but I can’t figure out how to declare a matrix (or higher dimensional array) variable that is constrained to a parameter set in JuMP, as shown for the vector case here: [Variables · JuMP](https://jump.dev/JuMP.jl/stable/manual/variables/#Parameters)

I tried different things like

> @variable(model, p[1:2,1:2] in Parameter(zeros(2,2)))

but none of them worked. Does anybody know how I should go about defining this?

Thank you.

---

<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:** [September 22, 2023, 11:35pm UTC](https://discourse.julialang.org/t/creating-matrix-parameters-in-jump/104159/2 "2023-09-22T23:35:05Z")

</div>

Hmm. It should be this, but it looks like there is a bug. Let me take a look.

```julia
julia> model = Model();

julia> @variable(model, p[1:2, 1:2] in Parameter(0.0))
ERROR: MethodError: no method matching build_variable(::JuMP.var"#_error#111"{LineNumberNode}, ::Matrix{ScalarVariable{Float64, Float64, Float64, Float64}}, ::Parameter{Float64})

Closest candidates are:
  build_variable(::Function, ::AbstractVariable, ::AbstractScalarSet)
   @ JuMP ~/.julia/dev/JuMP/src/sets.jl:260
  build_variable(::Function, ::AbstractArray{<:ScalarVariable}, ::MathOptInterface.AbstractScalarSet)
   @ JuMP ~/.julia/dev/JuMP/src/macros.jl:2188
  build_variable(::Function, ::AbstractArray{<:ScalarVariable}, ::AbstractArray{<:MathOptInterface.AbstractScalarSet})
   @ JuMP ~/.julia/dev/JuMP/src/macros.jl:2173
  ...

Stacktrace:
 [1] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:1218 [inlined]
 [2] top-level scope
   @ REPL[19]:1

```

Edit: [More Parameter woes · Issue #3523 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/3523)

---

<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:** [September 23, 2023, 12:15am UTC](https://discourse.julialang.org/t/creating-matrix-parameters-in-jump/104159/3 "2023-09-23T00:15:47Z")

</div>

I have a PR to fix this: [Fix constructing an array of Parameter variables by odow · Pull Request #3524 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/pull/3524)

Parameters were added fairly recently, so a few cases slipped past me. Sorry for the confusion!

---

<div class="post-metadata">

**Author:** ![Three](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@Three](https://discourse.julialang.org/u/Three)\
**Post date:** [September 24, 2023, 6:05pm UTC](https://discourse.julialang.org/t/creating-matrix-parameters-in-jump/104159/4 "2023-09-24T18:05:46Z")

</div>

Thank you!
