# \[JuMP\] Get variable name from a model to use on another

**URL:** <https://discourse.julialang.org/t/jump-get-variable-name-from-a-model-to-use-on-another/10692>\
**Category:** Optimization (Mathematical)\
**Created:** [May 3, 2018, 10:00pm UTC](https://discourse.julialang.org/t/jump-get-variable-name-from-a-model-to-use-on-another/10692 "2018-05-03T22:00:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [May 3, 2018, 10:00pm UTC](https://discourse.julialang.org/t/jump-get-variable-name-from-a-model-to-use-on-another/10692/1 "2018-05-03T22:00:01Z")

</div>

On `JuMP`, I have a model

```julia
m = Model()
@variable(m, x[1:2])

```

By passing `m` to a function, can I obtain the variable `x` to define a new model with `x`?

---

<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:** [May 3, 2018, 10:49pm UTC](https://discourse.julialang.org/t/jump-get-variable-name-from-a-model-to-use-on-another/10692/2 "2018-05-03T22:49:14Z")

</div>

> can I obtain the variable x

Yes `m[:x]`.

> to define a new model with x?

No. `x` belongs to the model `m`.

Do you want to make a variable with the same name? Or bounds? Or indices? If so, just pass the necessary data to build the variable rather than the model and actual variable.

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [May 4, 2018, 4:18pm UTC](https://discourse.julialang.org/t/jump-get-variable-name-from-a-model-to-use-on-another/10692/3 "2018-05-04T16:18:04Z")

</div>

Thanks @odow, but I must clarify. I don’t know which variables the model has, that is, instead of defining `x`, an user could define only `y`.

This is related to another problem and the context is clearer [there](https://discourse.julialang.org/t/jump-creating-a-nonlinear-least-squares-model/10706).

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [May 5, 2018, 7:51pm UTC](https://discourse.julialang.org/t/jump-get-variable-name-from-a-model-to-use-on-another/10692/4 "2018-05-05T19:51:04Z")

</div>

Solved in the other post.
