JuliaNLSolvers / NLsolve.jl

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

Non-convergance of simple goniometric functions #269

Closed lieskjur closed 3 years ago

lieskjur commented 3 years ago

Hi, I wrote a very simple problem to test out NLsolve for systems of goniometric equations:

using NLsolve
using Rotations
using StaticArrays

j = @SVector [0,1,0]
v = @SVector [0,cos(pi/3),sin(pi/3)]

function g!(G,ϕϕ)
    G = RotX(ϕϕ[1])*RotY(ϕϕ[2])*j - v
end

nlsolve(g!,[pi/4;0])

(RotX and RotY follow the convention as in https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions) which for some reason does not converge

julia> nlsolve(g!,[pi/4;0])                                                                          
Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [1.5707963267948966, 0.0]
 * Zero: [NaN, NaN]
 * Inf-norm of residuals: 1.570796
 * Iterations: 1
 * Convergence: false
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: false
 * Function Calls (f): 2
 * Jacobian Calls (df/dx): 1

My guess would be that there is no appropriate algorithm for solving the problem implemented in NLsolve as when solving the problem with matlab's fsolve() it switches from "Trust-region-dogleg" to "Levenberg-Marquardt" because the problem is non-square and the "Newton method" in NLsolve can't be used either as it results in

ERROR: DomainError with -Inf:
sincos(x) is only defined for finite x.

Am I correct or did I miss something very basic? (I am very new to NLsolve and Julia in general)