JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

First example in Readme does not work

benjaminfreyd opened this issue · comments

I just copy-pasted the code in Julia 1.5.3.

using NLsolve

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

function j!(J, x)
    J[1, 1] = x[2]^3-7
    J[1, 2] = 3*x[2]^2*(x[1]+3)
    u = exp(x[1])*cos(x[2]*exp(x[1])-1)
    J[2, 1] = x[2]*u
    J[2, 2] = u
end

nlsolve(f!, j!, [ 0.1; 1.2])

Which returns

MethodError: no method matching j!(::Array{Float64,1})
Closest candidates are:
  j!(::Any, !Matched::Any) at In[21]:8

It works fine on my end


julia> using NLsolve

julia> function f!(F, x)
           F[1] = (x[1]+3)*(x[2]^3-7)+18
           F[2] = sin(x[2]*exp(x[1])-1)
       end
f! (generic function with 1 method)

julia> function j!(J, x)
           J[1, 1] = x[2]^3-7
           J[1, 2] = 3*x[2]^2*(x[1]+3)
           u = exp(x[1])*cos(x[2]*exp(x[1])-1)
           J[2, 1] = x[2]*u
           J[2, 2] = u
       end
j! (generic function with 1 method)

julia> nlsolve(f!, j!, [ 0.1; 1.2])
Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [0.1, 1.2]
 * Zero: [-3.7818049096324184e-16, 1.0000000000000002]
 * Inf-norm of residuals: 0.000000
 * Iterations: 4
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 5
 * Jacobian Calls (df/dx): 5