Is NonlinearSolve.jl the right package?

What is the equivalent way to do this in julia?

I wasn’t able to figure it out.

1 Like

Here you go:

julia> using NonlinearSolve

julia> function equations(vars, params)
           h, k = vars
           d_c = 18.0
           y_0 = 0.0
           length = 135.0
           height = 180.0
           eq1 = (d_c - h)^2 + (y_0 - k)^2 - 480^2
           eq2 = (length - h)^2 + (height - k)^2 - 480^2
           return [eq1, eq2]
       end
equations (generic function with 1 method)

julia> initial_guess = [400.0, -400.0]
2-element Vector{Float64}:
  400.0
 -400.0

julia> prob = NonlinearSolve.NonlinearProblem(equations, initial_guess)
NonlinearProblem with uType Vector{Float64}. In-place: false
u0: 2-element Vector{Float64}:
  400.0
 -400.0

julia> sol = NonlinearSolve.solve(prob)
sretcode: Success
u: 2-element Vector{Float64}:
  468.7605837368863
 -164.96937942897614

julia> sol.u
2-element Vector{Float64}:
  468.7605837368863
 -164.96937942897614
3 Likes

Solving a (linear/nonlinear) equation system is nothing other than an optimization without an objective. I guess IPOPT can also do this work (possibly even automatically grab an initial guess for you).

generally optimizers are much less efficient than linear/nonlinear solvers.

3 Likes