API
RootSolvers
RootSolvers.RootSolvers
— ModuleRootSolvers
Contains functions for solving roots of non-linear equations. See find_zero
.
Example
julia> using RootSolvers
julia> sol = find_zero(x -> x^2 - 100^2,
SecantMethod{Float64}(0.0, 1000.0),
CompactSolution());
julia> sol
CompactSolutionResults{Float64}:
├── Status: converged
└── Root: 99.99999999994358
julia> sol.root
99.99999999994358
Numerical methods
RootSolvers.find_zero
— Functionsol = find_zero(
f::F,
method::RootSolvingMethod{FT},
soltype::SolutionType,
tol::Union{Nothing, AbstractTolerance} = nothing,
maxiters::Int = 10_000,
)
Finds the nearest root of f
. Returns a the value of the root x
such that f(x) ≈ 0
, and a Boolean value converged
indicating convergence.
f
function of the equation to find the rootmethod
can be one of:SecantMethod()
: Secant methodRegulaFalsiMethod()
: Regula Falsi methodNewtonsMethodAD()
: Newton's method using Automatic DifferentiationNewtonsMethod()
: Newton's method
soltype
is a solution type which may be one of:CompactSolution
GPU-capable. Solution hasconverged
androot
only, seeCompactSolutionResults
VerboseSolution
CPU-only. Solution has additional diagnostics, seeVerboseSolutionResults
tol
is a tolerance type to determine when to stop iterations.maxiters
is the maximum number of iterations.
RootSolvers.NewtonsMethodAD
— TypeNewtonsMethodAD
Fields
x0
initial guess
RootSolvers.NewtonsMethod
— TypeNewtonsMethod
Fields
x0
initial guess
RootSolvers.RegulaFalsiMethod
— TypeRegulaFalsiMethod
Fields
x0
lower boundx1
upper bound
RootSolvers.SecantMethod
— TypeSecantMethod
Fields
x0
lower boundx1
upper bound
Solution types
RootSolvers.CompactSolution
— TypeCompactSolution <: SolutionType
Used to return a CompactSolutionResults
RootSolvers.VerboseSolution
— TypeVerboseSolution <: SolutionType
Used to return a VerboseSolutionResults
RootSolvers.VerboseSolutionResults
— TypeVerboseSolutionResults{FT} <: AbstractSolutionResults{FT}
Result returned from find_zero
when VerboseSolution
is passed as the soltype
.
RootSolvers.CompactSolutionResults
— TypeCompactSolutionResults{FT} <: AbstractSolutionResults{FT}
Result returned from find_zero
when CompactSolution
is passed as the soltype
.
To extract the root, use
sol = RootSolvers.find_zero(...)
sol.root
Tolerance types
RootSolvers.ResidualTolerance
— TypeResidualTolerance
A tolerance type based on the residual of the equation $f(x) = 0$
RootSolvers.SolutionTolerance
— TypeSolutionTolerance
A tolerance type based on the solution $x$ of the equation $f(x) = 0$
RootSolvers.RelativeSolutionTolerance
— TypeRelativeSolutionTolerance
A tolerance type based on consecutive iterations of solution $x$ of the equation $f(x) = 0$
RootSolvers.RelativeOrAbsoluteSolutionTolerance
— TypeRelativeOrAbsoluteSolutionTolerance(rtol, atol)
A combined tolerance type based on relative and absolute tolerances.
Internal helper methods
RootSolvers.value_deriv
— Functionvalue_deriv(f, x)
Compute the value and derivative f(x)
using ForwardDiff.jl.
RootSolvers.method_args
— Functionmethod_args(method::RootSolvingMethod)
Return tuple of positional args for RootSolvingMethod
.