Given other input values, function nls_obj maps delta to a real number, but this function does not have an analytical form. When I feed a value of delta into it, the function works as expected. However, the optimization reports error message:
ERROR: MethodError: no method matching optimize(::var"#382#383", ::Int64, ::LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#19#21"}, ::Optim.Options{Float64,Nothing})
Is it because I call the optimization in a wrong way?
Ok, seems like an issue with the function you are minimizing, but it’s impossible to say without more information. Please at least post the full stacktrace and ideally a minimal reproducible example. See Please read: make it easier to help you for more information about making it easier for us to help you.
I think that it’s a problem that nls_obj returns two outputs (well, actually, it returns a length-2 tuple. How could you find the minimum among tuples?). Try making your anonymous objective function only return the first output (if that is what you need).
This is a plot for the objective of minimization. Depending on initial value, the solution is either the global minimum or a very negative value which gives a local minimum.