Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First example in Readme does not work #266

Open
benjaminfreyd opened this issue Feb 7, 2021 · 1 comment
Open

First example in Readme does not work #266

benjaminfreyd opened this issue Feb 7, 2021 · 1 comment

Comments

@benjaminfreyd
Copy link

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
@pkofod pkofod transferred this issue from JuliaNLSolvers/Optim.jl Feb 11, 2021
@pkofod
Copy link
Member

pkofod commented Feb 11, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants