# On the output value of JuMP

**URL:** https://discourse.julialang.org/t/on-the-output-value-of-jump/44084
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [August 1, 2020, 1:41pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084 "2020-08-01T13:41:17Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)
#### Post date: [August 1, 2020, 1:41pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/1 "2020-08-01T13:41:17Z")

</div>

How to output the value of my decision variable in workspace？  
I tried to use value at the end of the program, but it didn’t work. At present, the effective way is to write value() one by one in repl.

 ![11](https://global.discourse-cdn.com/julialang/original/3X/0/8/087a0a948e18f2186f73b81945214b53a5dcf278.png)

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [August 1, 2020, 2:05pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/2 "2020-08-01T14:05:21Z")

</div>

If each variable is a single value (not an array of values), I think the best way is (maybe):

```julia
for variable in all_variables(model)
    println("$(name(variable)) = $(value(variable))")
end

```

Also, maybe you wanna put it inside an `if` too, to avoid printing the zero-valued variables.

---

<div class="post-metadata">

### Author: ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)
#### Post date: [August 1, 2020, 2:09pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/3 "2020-08-01T14:09:57Z")

</div>

What if the variables in matrix form need to be output？

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [August 1, 2020, 2:23pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/4 "2020-08-01T14:23:30Z")

</div>

My first reply will work if some variables are, in fact, vectors or matrices of variables. But, then, maybe you wanna do something special to improve the visualization, I mean. Using that loop you will get:

```julia
scalar_name = its_value
matrix[1, 1] = its_value
matrix[1, 2] = its_value
...
scalar_name = its_value 

```

The order will be by creation time (unless you start to fiddle with the JuMP containers yourself).

---

<div class="post-metadata">

### Author: ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)
#### Post date: [August 1, 2020, 2:37pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/5 "2020-08-01T14:37:09Z")

</div>

Assign the value to some variable `PGD_EX_opt = value(PGD_EX)`

> [@dty](#):
>
> What if the variables in matrix form need to be output

In that case don’t forget to use the `.` broadcast in `value`

```julia
M_opt = value.(M)

```

---

<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: [August 1, 2020, 3:03pm UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/6 "2020-08-01T15:03:02Z")

</div>

If your decision variable is a vector use value.(variable)

---

<div class="post-metadata">

### Author: ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)
#### Post date: [August 3, 2020, 9:21am UTC](https://discourse.julialang.org/t/on-the-output-value-of-jump/44084/7 "2020-08-03T09:21:35Z")

</div>

that’s right! thankyou!
