# Nested Sum in NLObjective -

**URL:** <https://discourse.julialang.org/t/nested-sum-in-nlobjective/96890>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, ipopt\
**Created:** [March 31, 2023, 12:42pm UTC](https://discourse.julialang.org/t/nested-sum-in-nlobjective/96890 "2023-03-31T12:42:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregoryo](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Gregoryo](https://discourse.julialang.org/u/Gregoryo)\
**Post date:** [March 31, 2023, 12:42pm UTC](https://discourse.julialang.org/t/nested-sum-in-nlobjective/96890/1 "2023-03-31T12:42:38Z")

</div>

Hi, I am totally new to both Julia and Optimization and I am trying to define a non linear objective that requires nested sums. I found some examples that I am trying to replicate, but I get an error. This is how I set my nested NLObjective

@NLobjective(my\_model, :Min, Sum(Sum((Sum( m[i]\* exp((X[j]-x[i])^2/gamma^2) \* exp((Y[k]-y[i])^2/gamma^2) for i=1:np) - C[j,k])^2 for j in eachindex(X)) for k in eachindex(Y)))

Where m, x and y are my arrays of variables and X, Y and C are arrays of predefined parameters.

I am getting the following error and eBay help is hugely appreciated:

LoadError: Unsupported generator `:Sum`  
Stacktrace:  
[1] error(s::String)  
@ Base ./error.jl:35  
[2] \_parse\_generator\_expression(code::Expr, x::Expr, operators::Set{Tuple{Symbol, Int64}})  
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:2008  
[3] \_parse\_nonlinear\_expression\_inner(code::Expr, x::Expr, operators::Set{Tuple{Symbol, Int64}})  
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:1968  
[4] \_parse\_nonlinear\_expression(model::Expr, x::Expr)  
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:1876  
[5] var"@NLobjective"( **source** ::LineNumberNode, **module** ::Module, model::Any, sense::Any, x::Any)  
@ JuMP ~/.julia/packages/JuMP/9CBpS/src/macros.jl:2393  
in expression starting at /Users/Greg/Documents/OneDrive/Documents/Julia Code/Scalar points optimizer:41  
in expression starting at /Users/Greg/Documents/OneDrive/Documents/Julia Code/Scalar points optimizer:41

---

<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:** [March 31, 2023, 1:04pm UTC](https://discourse.julialang.org/t/nested-sum-in-nlobjective/96890/2 "2023-03-31T13:04:29Z")

</div>

Try it with a lowercase s, i.e. `sum`, not `Sum`.

---

<div class="post-metadata">

**Author:** ![Gregoryo](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Gregoryo](https://discourse.julialang.org/u/Gregoryo)\
**Post date:** [March 31, 2023, 3:06pm UTC](https://discourse.julialang.org/t/nested-sum-in-nlobjective/96890/3 "2023-03-31T15:06:00Z")

</div>

Hey Abel, thank you so much. it all works. Sometimes, things are so big that you cannot see them. You have a great rest of your day. Cheers, Greg
