# How to get @NLparameter in a model?

**URL:** <https://discourse.julialang.org/t/how-to-get-nlparameter-in-a-model/6750>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [October 28, 2017, 10:35pm UTC](https://discourse.julialang.org/t/how-to-get-nlparameter-in-a-model/6750 "2017-10-28T22:35:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CanLi1](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@CanLi1](https://discourse.julialang.org/u/CanLi1)\
**Post date:** [October 28, 2017, 10:35pm UTC](https://discourse.julialang.org/t/how-to-get-nlparameter-in-a-model/6750/1 "2017-10-28T22:35:59Z")

</div>

For variables and constraints, we can use the function getindex(m, :x) to get the variable or constraints.  
But for @NLparameter defined in a model, getindex doesn’t work for me. Does anyone know how to get the NLparameter in a model. Many thanks!

Best regards,  
Can

---

<div class="post-metadata">

**Author:** ![JackDevine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackdevine/32/1048_2.png) [@JackDevine](https://discourse.julialang.org/u/JackDevine)\
**Post date:** [October 30, 2017, 12:59am UTC](https://discourse.julialang.org/t/how-to-get-nlparameter-in-a-model/6750/2 "2017-10-30T00:59:15Z")

</div>

You could register the parameter to your model,

```julia
p = :x
JuMP.registerobject(m, p, eval(p), "Warning: $(p) has already been registered.")

```

Although, I am not sure if that is the recommended way of doing things.

Also, make sure that you surround code with backticks, particularly when you are referring to a macro. Otherwise somebody called NLparameter might get pinged (not very likely in this case, but it could happen in general).

---

<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:** [October 30, 2017, 1:26am UTC](https://discourse.julialang.org/t/how-to-get-nlparameter-in-a-model/6750/3 "2017-10-30T01:26:33Z")

</div>

`@NLparameter` objects aren’t automatically stored in the model dictionary. But you can just put them there if you want:

```julia
@NLparameter(m, p == 1)
m[:p] = p

```

---

<div class="post-metadata">

**Author:** ![CanLi1](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@CanLi1](https://discourse.julialang.org/u/CanLi1)\
**Post date:** [October 30, 2017, 2:38am UTC](https://discourse.julialang.org/t/how-to-get-nlparameter-in-a-model/6750/4 "2017-10-30T02:38:54Z")

</div>

Thanks a lot!
