Help with NonlinearSolve.jl

https://github.com/SciML/NonlinearSolve.jl/pull/50

using StaticArrays
using NonlinearSolve

function f(x, _)
    F1 = (x[1] + 3) * (x[2]^3 - 7) + 18
    F2 = sin(x[2] * exp(x[1]) - 1)
    SA[F1,F2]
end

function f!(F, x)
    F[1] = (x[1] + 3) * (x[2]^3 - 7) + 18
    F[2] = sin(x[2] * exp(x[1]) - 1)
    nothing
end

x0 = [0.1; 1.2]
x0s = SVector{size(x0)...}(x0)
x0m = MVector{size(x0)...}(x0)
prob = NonlinearProblem{false}(f, x0s)

using NLsolve, BenchmarkTools
@btime sol = solve(prob,NewtonRaphson()); # 320.000 ns (2 allocations: 128 bytes)
@btime nlsolve(f!, x0m); # 1.460 μs (35 allocations: 1.36 KiB)

That is probably more of what you are looking for.

1 Like