# Sensitivity analysis in optimization

**URL:** https://discourse.julialang.org/t/sensitivity-analysis-in-optimization/20833
**Category:** Optimization (Mathematical)
**Created:** [February 15, 2019, 7:01pm UTC](https://discourse.julialang.org/t/sensitivity-analysis-in-optimization/20833 "2019-02-15T19:01:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rev](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@rev](https://discourse.julialang.org/u/rev)
#### Post date: [February 15, 2019, 7:01pm UTC](https://discourse.julialang.org/t/sensitivity-analysis-in-optimization/20833/1 "2019-02-15T19:01:58Z")

</div>

Hello All,

New to Optimization & JuMP. Trying to do sensitivity analysis for this example, and wondering how to get reduced costs, objective coefficients, allowable increase/decrease, shadow prices, and final values for given constraints. They are very easy to get on excel solver. Read through the documentation here, [Expressions and Constraints — JuMP -- Julia for Mathematical Optimization 0.18 documentation](http://www.juliaopt.org/JuMP.jl/v0.18/refexpr.html), but not helpful.

Please advice.

```julia
#Initialise values
n=4;r=[.1;.15;.16; 0.08]
A = [1 1 1 1]
b = 80
D = [.5 .3 .25 .6; .3 .1 .4 .2; .2 .6 .35 .2]
d = [28; 24; 12]

using JuMP
using Gurobi

#Define Model
model = Model(solver=GurobiSolver(Presolve=0))

#Define variables
@variable(model, x[1:4])
#Define Objective
@objective(model, Max, r'*x)
#Define constraints
@constraints model begin
       x .>= zeros(1,4)
       A*x .== b
       D*x .>= d
end

status = solve(model)

getvalue(x) # Giving correct final values

println(getdual(x)) # The duals are shown as zeros

```

---

<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: [February 15, 2019, 8:07pm UTC](https://discourse.julialang.org/t/sensitivity-analysis-in-optimization/20833/2 "2019-02-15T20:07:49Z")

</div>

Much of what you are asking for (e.g. allowable increase/decrease) isn’t implemented in JuMP. See  
[https://github.com/JuliaOpt/JuMP.jl/issues/1332](https://github.com/JuliaOpt/JuMP.jl/issues/1332)

`getdual(x)` returns the dual variable associated with a variable bound. Since you don’t have bounds on your variables, this is `0.0`.

`getdual` does work on constraints though:

```julia
@constraint(model, my_constraint, sum(x) <= 1)
getdual(my_constraint)

```

---

<div class="post-metadata">

### Author: ![ajkeith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ajkeith/32/970_2.png) [@ajkeith](https://discourse.julialang.org/u/ajkeith)
#### Post date: [February 15, 2019, 9:00pm UTC](https://discourse.julialang.org/t/sensitivity-analysis-in-optimization/20833/3 "2019-02-15T21:00:33Z")

</div>

I’m not sure if what you need is included, but if you use [Clp](https://github.com/JuliaOpt/Clp.jl) as your solver, you can access the Clp C interface with `using Clp.ClpCInterface` to get access to more detailed solution information.
