# How to evaluate MathProgBase functions of a JuMP model

**URL:** <https://discourse.julialang.org/t/how-to-evaluate-mathprogbase-functions-of-a-jump-model/29303>\
**Category:** Optimization (Mathematical)\
**Created:** [September 29, 2019, 11:00pm UTC](https://discourse.julialang.org/t/how-to-evaluate-mathprogbase-functions-of-a-jump-model/29303 "2019-09-29T23:00:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahbubar06](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Mahbubar06](https://discourse.julialang.org/u/Mahbubar06)\
**Post date:** [September 29, 2019, 11:00pm UTC](https://discourse.julialang.org/t/how-to-evaluate-mathprogbase-functions-of-a-jump-model/29303/1 "2019-09-29T23:00:34Z")

</div>

I have a JuMP model and I want to evaluate the following functions for this model: MathProgBase.eval\_f(), MathProgBase.eval\_g(), MathProgBase.jac\_structure(), MathProgBase.eval\_grad\_f(). The model is as the following:

```julia
Min (x[1] ^ 2.0 + x[2] ^ 2.0 + x[3] ^ 2.0) + x[4] + x[5]
Subject to
 x[1] + x[2] + x[3] + x[4] + x[5] <= 50
 (x[1] ^ 2.0 + x[2] ^ 2.0 + x[3] ^ 2.0 + x[4] ^ 2.0 + x[5] ^ 2.0) - 100.0 <= 0
 (x[1] ^ 2.0 + x[2] ^ 2.0 + x[3] ^ 2.0) - 50.0 <= 0
 -100 <= x[i] <= 100 for all i in {1,2,3,4,5}

```

The julia code for the JuMP (version 0.18) model is the following:

```julia
using JuMP
using MathProgBase
using Ipopt
model=Model(solver=IpoptSolver())
@variable(model, -100 <= x[1:5] <=100)
@NLconstraint(model, sum(x[i]^2 for i in 1:5) <= 100)
@NLconstraint(model, sum(x[i]^2 for i in 1:5) <= 100)
@constraint(model, sum(x[i] for i in 1:5) <= 50)
@NLconstraint(model, sum(x[i]^2 for i in 1:3) <= 50)
@NLobjective(model, Min, sum(x[i]^2 for i in 1:3)+x[4]+x[5])

```

I need a guideline so that I can execute the above mentioned functions for the NLP model. Thank you.

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [September 30, 2019, 3:05am UTC](https://discourse.julialang.org/t/how-to-evaluate-mathprogbase-functions-of-a-jump-model/29303/2 "2019-09-30T03:05:05Z")

</div>

See [Nonlinear Modeling — JuMP -- Julia for Mathematical Optimization 0.18 documentation](http://www.juliaopt.org/JuMP.jl/v0.18.0/nlp.html#querying-derivatives-from-a-jump-model).

---

<div class="post-metadata">

**Author:** ![Mahbubar06](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Mahbubar06](https://discourse.julialang.org/u/Mahbubar06)\
**Post date:** [September 30, 2019, 5:04am UTC](https://discourse.julialang.org/t/how-to-evaluate-mathprogbase-functions-of-a-jump-model/29303/3 "2019-09-30T05:04:18Z")

</div>

This link helps. Thank you @miles.lubin.
