# API

## Numerical methods

### Find zero

ConstrainedRootSolvers.find_zeroFunction

Function to find the first root that gives a target function result of zero. If the root does not exist, the function returns the point where the target function is most close to zero.

find_zero(f, ms, tol; stepping)
find_zero(f, ms, tol; stepping)
find_zero(f, ms, tol; stepping)
find_zero(f, ms, tol; stepping)
ConstrainedRootSolvers.find_zeroMethod

This method uses BisectionMethod method:

find_zero(f::Function,
ms::BisectionMethod{FT},
tol::Union{ResidualTolerance{FT}, SolutionTolerance{FT}};
stepping::Bool = false
) where {FT<:AbstractFloat}

Returns the solution where target function is zero, given

ConstrainedRootSolvers.find_zeroMethod

This method uses NewtonBisectionMethod method:

find_zero(f::Function,
ms::NewtonBisectionMethod{FT},
tol::Union{ResidualTolerance{FT}, SolutionTolerance{FT}};
stepping::Bool = false
) where {FT<:AbstractFloat}

Returns the solution where target function is zero, given

ConstrainedRootSolvers.find_zeroMethod

This method uses NewtonRaphsonMethod method:

find_zero(f::Function,
ms::NewtonRaphsonMethod{FT},
tol::Union{ResidualTolerance{FT}, SolutionTolerance{FT}};
stepping::Bool = false
) where {FT<:AbstractFloat}

Returns the solution where target function is zero, given

ConstrainedRootSolvers.find_zeroMethod

This method uses ReduceStepMethod method:

find_zero(f::Function,
ms::ReduceStepMethod{FT},
tol::Union{ResidualTolerance{FT}, SolutionTolerance{FT}};
stepping::Bool = false
) where {FT<:AbstractFloat}

Returns the solution where target function is zero, given

### Find peak

ConstrainedRootSolvers.find_peakFunction

Function to find the first root that gives a target function result of maximum. Note that to compute the lowest value, use -f to make it a peak.

find_peak(f, ms, tol; stepping)
find_peak(f, ms, tol; stepping)
find_peak(f, ms, tol)
find_peak(f, ms, tol)
find_peak(f, ms, tol)

## Method options

ConstrainedRootSolvers.BisectionMethodType

Bisection method for 1D root solvers

mutable struct BisectionMethod{FT<:AbstractFloat} <: ConstrainedRootSolvers.AbstractCRSMethod{FT<:AbstractFloat}

Fields

• x_min::AbstractFloat

lower bound

• x_max::AbstractFloat

upper bound

• xy::Matrix{FT} where FT<:AbstractFloat

matrix that stores x and y, used in find_peak

• history::Vector

history of all simulations

ConstrainedRootSolvers.NelderMeadMethodType

Nelder-Mead method for 2D and above solvers

mutable struct NelderMeadMethod{FT<:AbstractFloat} <: ConstrainedRootSolvers.AbstractCRSMethod{FT<:AbstractFloat}

Fields

• N::Int64

Number of parameters to optimize

• x_inis::Vector{FT} where FT<:AbstractFloat

Initial values

• simplex::Array{Vector{FT}, 1} where FT<:AbstractFloat

Simplex vector of vector with dimension (N+1) * (N+1)

• cen_x::Vector{FT} where FT<:AbstractFloat

Centroid

• ref_x::Vector{FT} where FT<:AbstractFloat

Reflection

• exp_x::Vector{FT} where FT<:AbstractFloat

Expansion

• con_x::Vector{FT} where FT<:AbstractFloat

Contraction

• history::Array{Vector{FT}, 1} where FT<:AbstractFloat

history of all simulations

ConstrainedRootSolvers.NewtonBisectionMethodType

Newton's method constrained by mininum and maximum ranges for 1D root solver

mutable struct NewtonBisectionMethod{FT<:AbstractFloat} <: ConstrainedRootSolvers.AbstractCRSMethod{FT<:AbstractFloat}

Fields

• x_min::AbstractFloat

Lower bound

• x_max::AbstractFloat

Upper bound

• x_ini::AbstractFloat

Initial guess

• history::Vector

history of all simulations

ConstrainedRootSolvers.NewtonRaphsonMethodType

Newton raphson method for 1D root solver

mutable struct NewtonRaphsonMethod{FT<:AbstractFloat} <: ConstrainedRootSolvers.AbstractCRSMethod{FT<:AbstractFloat}

Fields

• x_ini::AbstractFloat

Initial guess

• history::Vector

history of all simulations

ConstrainedRootSolvers.ReduceStepMethodType

Reduce step method for 1D root solver. This method increases or decreases from initial guess until no improvement is found. Then the incremantal step decreases, and then the root solver continues.

mutable struct ReduceStepMethod{FT<:AbstractFloat} <: ConstrainedRootSolvers.AbstractCRSMethod{FT<:AbstractFloat}

Fields

• x_min::AbstractFloat

Lower bound

• x_max::AbstractFloat

Upper bound

• x_ini::AbstractFloat

Initial guess

• Δ_ini::AbstractFloat

Initial step

• history::Vector

history of all simulations

ConstrainedRootSolvers.ReduceStepMethodNDType

Reduce step method for 2D and above root solver. This method increases or decreases each variable in the initial guess until no improvement is found. Then the incremental steps decreases, and then the root solver continues.

mutable struct ReduceStepMethodND{FT<:AbstractFloat} <: ConstrainedRootSolvers.AbstractCRSMethod{FT<:AbstractFloat}

Fields

• x_mins::Vector{FT} where FT<:AbstractFloat

Lower bound

• x_maxs::Vector{FT} where FT<:AbstractFloat

Upper bound

• x_inis::Vector{FT} where FT<:AbstractFloat

Initial guess

• x_targ::Vector{FT} where FT<:AbstractFloat

Target x

• x_temp::Vector{FT} where FT<:AbstractFloat

Temporary x

• Δ_inis::Vector{FT} where FT<:AbstractFloat

Initial step

• Δ_oper::Vector{FT} where FT<:AbstractFloat

Operation step

• Δjd::Vector{Bool}

Vector of judges

## Tolerance options

ConstrainedRootSolvers.ResidualToleranceType

Tolerance for target function residual

struct ResidualTolerance{FT} <: ConstrainedRootSolvers.AbstractTolerance{FT}

Fields

• tol::Any

Tolerance for residual

• n_limit::Int64

limit of iterations

ConstrainedRootSolvers.SolutionToleranceType

Tolerance for solution

struct SolutionTolerance{FT} <: ConstrainedRootSolvers.AbstractTolerance{FT}

Fields

• tol::Any

Tolerance for solution

• n_limit::Int64

limit of iterations

ConstrainedRootSolvers.SolutionToleranceNDType

Tolerance for 2D and above solution

struct SolutionToleranceND{FT} <: ConstrainedRootSolvers.AbstractTolerance{FT}

Fields

• tol::Vector

Tolerance for solution

• n_limit::Int64

limit of iterations

ConstrainedRootSolvers.if_breakFunction

Determine whether to stopping finding the solution depending on the tolerance type.

if_break(tol, x1, x2, y, n)
if_break(tol, x1, x2, y, n)
ConstrainedRootSolvers.next_xy!Function
next_xy!(f::Function,
xy::Matrix{FT},
history::Vector{Vector{FT}},
stepping::Bool
) where {FT<:AbstractFloat}

Determine the next points to simulate, given

• f Function to find peak
• xy Matrix of x (1st column) and y (2nd column)
• history A vector to save simulations
• stepping Optional. If true, save the optimization steps to the history field in method struct.