# Get variable's value in JuMP

**URL:** <https://discourse.julialang.org/t/get-variables-value-in-jump/44596>\
**Category:** Optimization (Mathematical)\
**Created:** [August 9, 2020, 2:19am UTC](https://discourse.julialang.org/t/get-variables-value-in-jump/44596 "2020-08-09T02:19:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)\
**Post date:** [August 9, 2020, 2:19am UTC](https://discourse.julialang.org/t/get-variables-value-in-jump/44596/1 "2020-08-09T02:19:28Z")

</div>

Hi All,

I have solved an optimization problem using Julia (1.3.1) and JuMP (0.21.3). I can print the model and see the constraints. I also can get the objective function’s value using (objective\_value(model)) . However, I cannot get the variables’ value. I have tried different commands to do so including value.(x) but I get the following error. Please let me know how I can get the variables’ value. I am using MOsek as a solver.

```julia
ERROR: LoadError: UndefVArError: x not defined

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 9, 2020, 5:17am UTC](https://discourse.julialang.org/t/get-variables-value-in-jump/44596/2 "2020-08-09T05:17:36Z")

</div>

Seems like `x` doesn’t exist. Perhaps your variable is named something else, or defined in a different scope. Can you post the relevant code that 1. defines the variable `x`, and 2. tries to get its value after optimizing?

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [August 9, 2020, 5:41am UTC](https://discourse.julialang.org/t/get-variables-value-in-jump/44596/3 "2020-08-09T05:41:19Z")

</div>

> [@Rasoul](#):
>
> I have tried different commands to do so including value.(x) but I get the following error.

Try `value.(model[:x])`

[https://jump.dev/JuMP.jl/stable/variables/](https://jump.dev/JuMP.jl/stable/variables/)
