JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add nlsolve method for scalar functions?

stevengj opened this issue · comments

Would be nice to have a method for scalar functions, simply by dispatching on scalar initial values. In its simplest form, this could be:

nlsolve(f, initial_x::Number; kwargs...) =
    nlsolve(x -> f(x[]), fill(initial_x); kwargs...)

which works by wrapping and unwrapping 0-dimensional arrays. (Note: this requires JuliaNLSolvers/NLSolversBase.jl#141.) That way, for the case of scalar functions you wouldn't have to go to the trouble of wrapping in an array yourself.

Of course, in the longer run you could have optimized methods for the scalar (0-dimensional) case.

I think we just need to point more people to NonlinearSolve.jl for that. NLsolve.jl make a few too many assumptions and internally will put things in mutable structures anyways, so it's not going to be full performance. The true algorithm in that case should be just a fully non-allocating iteration, which is why NonlinearSolve.jl's native algorithms will do when presented with scalars and static arrays. NLsolve.jl is great for its trust region methods on medium sized equations, but on the large and small end it would need some overhauls.

I think we just need to point more people to NonlinearSolve.jl for that. NLsolve.jl make a few too many assumptions and internally will put things in mutable structures anyways, so it's not going to be full performance. The true algorithm in that case should be just a fully non-allocating iteration, which is why NonlinearSolve.jl's native algorithms will do when presented with scalars and static arrays. NLsolve.jl is great for its trust region methods on medium sized equations, but on the large and small end it would need some overhauls.

These improvements are already present in NLSolvers.jl as well. Though, I'm happy to accomodate any improvements until I get time to properly deprecate NLsolve.jl .