MINPACK.jl

Wrapper for cminpack multivariate root finding routines
Author sglyon
Popularity
17 Stars
Updated Last
6 Months Ago
Started In
February 2017

MINPACK

Build Status

Windows Build status

Coverage Status

codecov.io

Julia interface to cminpack, a C/C++ rewrite of the MINPACK software (originally in fortran).

Usage

Usage is quite simple, there are two main API methods:

fsolve(f!::Function, x0::Vector{Float64}, m::Int=length(x0); tol::Float64=1e-8,
       show_trace::Bool=false, tracing::Bool=false, method::Symbol=:hybr,
       iterations::Int=typemax(Int), io::IO=STDOUT, kwargs...)

fsolve(f!::Function, g!::Function, x0::Vector{Float64}, m::Int=length(x0);
       tol::Float64=1e-8, show_trace::Bool=false, tracing::Bool=false,
       method::Symbol=:hybr, iterations::Int=typemax(Int), io::IO=STDOUT,
       kwargs...)

The functions f! and g! should accept the current point (call it x) as the second argument and fill the first argument with the function values and Jacobian matrix, repsectively. If no Jacobian is passed, one will be approximated using finite differences.

Example:

julia> using MINPACK

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

julia> function g!(fjac, x)
           fjac[1, 1] = x[2]^3 - 7
           fjac[1, 2] = 3 * (x[1] + 3) * x[2]*x[2]
           fjac[2, 1] = x[2] * exp(x[1]) * cos(x[2] * exp(x[1]) - 1)
           fjac[2, 2] = exp(x[1]) * cos(x[2] * exp(x[1]) - 1)
           fjac
       end
g! (generic function with 2 methods)

julia> res_jac = fsolve(f!, g!, ones(2))
Results of Nonlinear Solver Algorithm
 * Algorithm: Modified Powell (User Jac, Expert)
 * Starting Point: [1.0, 1.0]
 * Zero: [6.05177e-12, 1.0]
 * Inf-norm of residuals: 0.000000
 * Convergence: true
 * Message: algorithm estimates that the relative error between x and the solution is at most tol
 * Total time: 0.033416 seconds
 * Function Calls: 0
 * Jacobian Calls (df/dx): 0

julia> res_nojac = fsolve(f!, ones(2))
Results of Nonlinear Solver Algorithm
 * Algorithm: Modified Powell
 * Starting Point: [1.0, 1.0]
 * Zero: [6.05138e-12, 1.0]
 * Inf-norm of residuals: 0.000000
 * Convergence: true
 * Message: algorithm estimates that the relative error between x and the solution is at most tol
 * Total time: 0.000024 seconds
 * Function Calls: 0
 * Jacobian Calls (df/dx): 0

The additional available keyword arguments captured by ;kwargs... vary by the method used.

The keyword argument method can take on different value depending on which method of fsolve you are calling.

Available methods for the version where only f! is pased are:

  • :hybr: Modified version of Powell's algorithm. Uses MINPACK routine hybrd1
  • :lm: Levenberg-Marquardt. Uses MINPACK routine lmdif1
  • :lmdif: Advanced Levenberg-Marquardt (more options available with ;kwargs...). See MINPACK routine lmdif for more information
  • :hybrd: Advacned modified version of Powell's algorithm (more options available with ;kwargs...). See MINPACK routine hybrd for more information

Available methods for the version where both f! and g! are passed are:

  • :hybr: Advacned modified version of Powell's algorithm with user supplied Jacobian. Additional arguments are available via ;kwargs.... See MINPACK routine hybrj for more information
  • :lm: Advanced Levenberg-Marquardt with user supplied Jacobian. Additional arguments are available via ;kwargs.... See MINPACK routine lmder for more information

Required Packages

No packages found.