JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems
Other
324 stars 66 forks source link

add nlsolve method for scalar functions? #272

Open stevengj opened 3 years ago

stevengj commented 3 years ago

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.

ChrisRackauckas commented 3 years ago

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.

pkofod commented 3 years ago

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 .