Good afternoon,

I had a look at previous topices on this subject and could not find the solution to my error.

I have an optimization problem with a non linear user defined objective function called `bk_obj`

. This function takes as argument the two unknown of my problem and a parameter called `D`

(that will vary in the full problem). It is first defined and then the problem which depends on `D`

is solved in another function. The problem is probably linked to the fact that my objective function mixes as argument unknow and parameter but I am not able to write it correctlyâ€¦

I get an error about the array dimension that I am not able to solve. I have two unknown so I thought the dimension 2 was correct when I register my user defined function.

Many many thanks for anyone that could help. And sorry if my mistake is obvious.

```
using JuMP
using Ipopt
using QuadGK
using Interpolations
using LineSearches
u(c) = (c).^3.0
function bk_obj(Sb::AbstractFloat,
cbar::AbstractFloat,
D::AbstractFloat)
c1_ND(Î¸) = D * cbar * Î¸ + Sb * 1.2
val1(Î¸) = u(c1_ND(Î¸))
return quadgk(val1, 0.1, 0.9)[1]
end
function model_creator(D::AbstractFloat)
m = Model(solver = IpoptSolver())
@variable(m, x[1:2])
JuMP.register(m, :bk_obj, 2, bk_obj, autodiff=true)
@NLobjective(m, Max, bk_obj(x[1], x[2], D) )
@NLconstraint(m, x[1] + x[2] >= 0.0 )
JuMP.solve(m)
return getvalue(x)
end
model_creator(1.2)
```

And the error is:

```
BoundsError: attempt to access 2-element Array{Float64,1} at index [1:3]
Stacktrace:
[1] throw_boundserror(::Array{Float64,1}, ::Tuple{UnitRange{Int32}}) at .\abstractarray.jl:484
[2] checkbounds at .\abstractarray.jl:449 [inlined]
[3] view at .\subarray.jl:134 [inlined]
[4] #forward_eval#7(::ReverseDiffSparse.UserOperatorRegistry, ::Function, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{ReverseDiffSparse.NodeData,1}, ::SparseArrays.SparseMatrixCSC{Bool,Int32}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\arquie\.julia\packages\ReverseDiffSparse\ZBur9\src\forward.jl:127
[5] #forward_eval at .\none:0 [inlined]
[6] forward_eval_all(::JuMP.NLPEvaluator, ::Array{Float64,1}) at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\nlp.jl:445
[7] eval_grad_f(::JuMP.NLPEvaluator, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\nlp.jl:496
[8] initialize(::JuMP.NLPEvaluator, ::Array{Symbol,1}) at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\nlp.jl:403
[9] loadproblem!(::Ipopt.IpoptMathProgModel, ::Int32, ::Int32, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Symbol, ::JuMP.NLPEvaluator) at C:\Users\arquie\.julia\packages\Ipopt\45sRy\src\MPBWrapper.jl:55
[10] _buildInternalModel_nlp(::Model, ::JuMP.ProblemTraits) at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\nlp.jl:1244
[11] #build#123(::Bool, ::Bool, ::JuMP.ProblemTraits, ::Function, ::Model) at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\solvers.jl:304
[12] #build at .\none:0 [inlined]
[13] #solve#120(::Bool, ::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Model) at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\solvers.jl:168
[14] solve at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\solvers.jl:150 [inlined]
[15] macro expansion at C:\Users\arquie\.julia\packages\JuMP\Xvn0n\src\macros.jl:314 [inlined]
[16] model_creator(::Float64) at .\In[3]:26
[17] top-level scope at In[3]:38
```