# How to use string in @nlexpression

**URL:** <https://discourse.julialang.org/t/how-to-use-string-in-nlexpression/79374>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization\
**Created:** [April 12, 2022, 10:11am UTC](https://discourse.julialang.org/t/how-to-use-string-in-nlexpression/79374 "2022-04-12T10:11:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [April 12, 2022, 10:11am UTC](https://discourse.julialang.org/t/how-to-use-string-in-nlexpression/79374/1 "2022-04-12T10:11:15Z")

</div>

Hi All,  
i want to create @NL expreesion on fly in JuMP. I am getting the below error.

```nohighlight
model = Model()
@variable(model, x[1:3])

@constraint(model, c2, x[1] + 2 * x[3] >= 2)

@constraint(model, c4, 4 <= 2 * x[2] <= 5)

@variable(model,x1[h in 1:5, i in 1:1, j in 1:2, k in 1:1,p in 1:2])
xx=[];
push!(xx,"(196.3769 + 0.00003780828 *x1[h,i,j,k,p] + (3.682656*(10)^-10) * (x1[h,i,j,k,p])^2)")
x
#zz=@NLexpression(model,sum(x1[h,i,j,k,p] *
#(196.3769 + 0.00003780828 *x1[h,i,j,k,p] + (3.682656*(10)^-10) * (x1[h,i,j,k,p])^2) for h in 1:1, i in 1:1 ,j in 1:2,k in 1:1, p in 1:2)

zz=@NLexpression(model,sum(x1[h,i,j,k,p] *xx[1] for h in 1:1, i in 1:1 ,j in 1:2,k in 1:1, p in 1:2)

Unexpected object (196.3769 + 0.00003780828 *x1[h,i,j,k,p] + (3.682656*(10)^-10) * (x1[h,i,j,k,p])^2) (of type String in nonlinear expression.
error(::String) at error.jl:33
_parse_NL_expr_runtime(::Model, ::String, ::Array{JuMP._Derivatives.NodeData,1}, ::Int64, ::Array{Float64,1}) at parse_nlp.jl:223
macro expansion at parse_nlp.jl:247 [inlined]
```

---

<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:** [April 12, 2022, 6:47pm UTC](https://discourse.julialang.org/t/how-to-use-string-in-nlexpression/79374/2 "2022-04-12T18:47:59Z")

</div>

You cannot use a string for this, you must construct an Expr instead.

Documentation [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nlp/#Raw-expression-input)
