Functions and types
RationalFunctionApproximation.Approximation
RationalFunctionApproximation.Barycentric
RationalFunctionApproximation.Barycentric
RationalFunctionApproximation.DiscretizedPath
RationalFunctionApproximation.RFIVector
Base.collect
Base.values
RationalFunctionApproximation.Res
RationalFunctionApproximation.aaa
RationalFunctionApproximation.add_node!
RationalFunctionApproximation.approximate
RationalFunctionApproximation.check
RationalFunctionApproximation.convergenceplot
RationalFunctionApproximation.decompose
RationalFunctionApproximation.degree
RationalFunctionApproximation.degrees
RationalFunctionApproximation.errorplot
RationalFunctionApproximation.get_history
RationalFunctionApproximation.minimax
RationalFunctionApproximation.nodes
RationalFunctionApproximation.poleplot
RationalFunctionApproximation.poles
RationalFunctionApproximation.poles
RationalFunctionApproximation.residues
RationalFunctionApproximation.rewind
RationalFunctionApproximation.roots
RationalFunctionApproximation.roots
RationalFunctionApproximation.Approximation Type
Approximation (type)
Approximation of a function on a domain.
Fields
original
: the original functiondomain
: the domain of the approximationfun
: the barycentric representation of the approximationallowed
: function to determine if a pole is allowedprenodes
: the prenodes of the approximationtest_points
: test points where residual was computedhistory
: all approximations in the iteration
RationalFunctionApproximation.Barycentric Type
Barycentric (type)
Barycentric representation of a rational function.
Fields
node
: the nodes of the rational functionvalue
: the values of the rational functionweight
: the weights of the rational functionwf
: the weighted values of the rational functionstats
: convergence statistics
RationalFunctionApproximation.Barycentric Type
Barycentric(node, value, weight, wf=value .* weight; stats=missing)
Construct a Barycentric
rational function.
Arguments
node::Vector
: interpolation nodesvalue::Vector
: values at the interpolation nodesweight::Vector
: barycentric weights
Keywords
wf::Vector = value .* weight
: weights times values
Returns
::Barycentric
: a barycentric rational interpolating function
Examples
julia> r = Barycentric([1, 2, 3], [1, 2, 3], [1/2, -1, 1/2])
Barycentric function with 3 nodes and values:
1.0=>1.0, 2.0=>2.0, 3.0=>3.0
julia> r(1.5)
1.5
RationalFunctionApproximation.DiscretizedPath Method
DiscretizedPath(path, s::AbstractVector; kwargs...)
DiscretizedPath(path, n::Integer=0; kwargs...)
Discretize a path, keeping the option of future making local refinements.
Arguments
path
: a ComplexCurve or ComplexPaths
: a vector of parameter valuesn
: number of points to discretize the path
Keyword arguments
refinement
: number of refinements to make between consecutive pointsmaxpoints
: maximum number of points ever allowed
RationalFunctionApproximation.RFIVector Type
Sequence of rational interpolants produced by an iteration.
Fields
nodes
: vector of interpolation nodesvalues
: vector of interpolation valuesweights
: matrix of all weights (upper triangle)len
: the number of nodes for each approximationbest
: the index of the best approximation
See also: approximate
Base.collect Function
collect(d::DiscretizedPath, which=:nodes)
Collect the points and parameters of a discretized path.
Arguments
d
: a DiscretizedPath objectwhich
: return the nodes if :nodes, test points if :test, or all if :all
Returns
- Tuple of two vectors: parameter values and points on the path
See also add_node!
, DiscretizedPath
.
Base.values Method
values(r) returns a vector of the nodal values of the rational interpolant r
.
RationalFunctionApproximation.Res Method
Res(r, z)
Returns the residue of the rational function r
at the point z
.
RationalFunctionApproximation.aaa Method
aaa(y, z)
aaa(f)
Adaptively compute a rational interpolant.
Arguments
discrete mode
y::AbstractVector{<:Number}
: values at nodesz::AbstractVector{<:Number}
: interpolation nodes
continuous mode
f::Function
: function to approximate on the interval [-1,1]
Keyword arguments
max_degree::Integer=150
: maximum numerator/denominator degree to usefloat_type::Type=Float64
: floating point type to use for the computationtol::Real=1000*eps(float_type)
: tolerance for stoppingstagnation::Integer=10
: number of iterations to determines stagnationstats::Bool=false
: return convergence statistics
Returns
r::Barycentric
: the rational interpolantstats::NamedTuple
: convergence statistics, if keywordstats=true
Examples
julia> z = 1im * range(-10, 10, 500);
julia> y = @. exp(z);
julia> r = aaa(z, y);
julia> degree(r) # both numerator and denominator
12
julia> first(nodes(r), 4)
4-element Vector{ComplexF64}:
0.0 - 6.272545090180361im
0.0 + 9.43887775551102im
0.0 - 1.1022044088176353im
0.0 + 4.909819639278557im
julia> r(1im * π / 2)
-2.637151617496356e-15 + 1.0000000000000002im
See also approximate
for approximating a function on a curve or region.
RationalFunctionApproximation.add_node! Method
add_node!(d::DiscretizedPath, idx)
Add a new node to the discretization, and return the indexes of all affected points. The indexes are valid on the points
and params
fields.
Arguments
d
: a DiscretizedPath objectidx
: a 2-element tuple, vector, orCartesianIndex
into theparams
field. This identifies
the point to be promoted to a node.
Returns
- A 2-element vector of
CartesianIndices
into theparams
andpoints
fields.
See also DiscretizedPath
, collect
.
RationalFunctionApproximation.approximate Method
approximate(f, domain)
Adaptively compute a rational interpolant on a continuous or discrete domain.
Arguments
Continuous domain
f::Function
: function to approximatedomain
: curve, path, or region from ComplexRegions
Discrete domain
f::Function
: function to approximatez::AbstractVector
: point set on which to approximate
Keywords
max_iter::Integer=150
: maximum number of iterations on node additionfloat_type::Type
: floating point type to use for the computation¹tol::Real=1000*eps(float_type)
: relative tolerance for stoppingallowed::Function
: function to determine if a pole is allowed²refinement::Integer=3
: number of test points between adjacent nodes (continuum only)stagnation::Integer=20
: number of iterations to determine stagnation
¹Default of float_type
is the promotion of float(1)
and the float type of the domain. ²Default is to disallow poles on the curve or in the interior of a continuous domain, or to accept all poles on a discrete domain. Use allowed=true
to allow all poles.
Returns
r::Approximation
: the rational interpolant
See also Approximation
, check
, rewind
.
Examples
julia> f = x -> tanh( 40*(x - 0.15) );
julia> r = approximate(f, unit_interval)
Barycentric{Float64, Float64} rational function of type (22, 22) on the domain: Path{Float64} with 1 curve
julia> ( r(0.3), f(0.3) )
(0.9999877116508015, 0.9999877116507956)
julia> check(r); # accuracy over the domain
[ Info: Max error is 1.58e-13
RationalFunctionApproximation.check Method
check(r; quiet=false, prenodes=false)
Check the accuracy of a rational approximation r
on its domain. Returns the test points and the error at those points.
Arguments
r::Approximation
: rational approximation
Keywords
quiet::Bool=false
: suppress @info outputprenodes::Bool=false
: return prenodes of the approximation as well
Returns
τ::Vector
: test pointserr::Vector
: error at test points
See also approximate
.
RationalFunctionApproximation.convergenceplot Method
convergenceplot(r)
Plot the convergence history of a rational approximation.
Markers show the maximum error on (the boundary of) the domain as a function of the numerator/denominator degree. A red marker indicates that the approximation has disallowed poles in its domain. A gold halo highlights the best approximation.
sourceRationalFunctionApproximation.decompose Method
decompose(r)
Return the roots, poles, and residues of the rational interpolant r
.
RationalFunctionApproximation.degree Method
degree(r) returns the degree of the denominator of the rational r
.
RationalFunctionApproximation.degrees Method
degrees(r) returns the degrees of the numerator and denominator of the rational r
.
RationalFunctionApproximation.errorplot Method
errorplot(r; use_abs=false)
Plot the pointwise error of an Approximation
on (the boundary of) its domain. If the error is not real, then the real and imaginary parts are plotted separately, unless use_abs=true
.
RationalFunctionApproximation.get_history Method
get_history(r::Approximation)
Parse the convergence history of a rational approximation.
Arguments
r::Approximation
: the approximation to get the history from
Returns
::Vector
: degrees of the approximations::Vector
: estimated maximum errors of the approximations::Vector{Vector}
: poles of the approximations::Vector{Vector}
: allowed poles of the approximations::Integer
: index of the best approximation
See also convergenceplot
.
RationalFunctionApproximation.minimax Function
minimax(r::Barycentric, f::Function, nsteps::Integer=20)
minimax(r::Approximation, nsteps::Integer=20)
Compute an approximately minimax rational approximation to a function f
on the nodes of a given rational function in barycentric form. The returned approximation has the same type as the first input argument.
The nsteps
argument controls the number of Lawson iterations. The default value is 20.
Examples
julia> f(x) = tanh( 40*(x - 0.15) );
julia> r = approximate(f, unit_interval, max_degree=8); # least-squares approximation
julia> check(r);
[ Info: Max error is 1.06e-02
julia> r̂ = minimax(r);
julia> check(r̂);
[ Info: Max error is 1.40e-03
RationalFunctionApproximation.nodes Method
nodes(r) returns a vector of the interpolation nodes of the rational interpolant.
sourceRationalFunctionApproximation.poleplot Method
poleplot(r, idx=0)
Plot the domain of the approximation r
and the poles of the rational approximant. If idx
is nonzero, it should be an index into the convergence history of r
.
RationalFunctionApproximation.poles Method
poles(r) returns the poles of the rational interpolant r
.
RationalFunctionApproximation.poles Method
poles(r)
Return the poles of the rational function r
.
RationalFunctionApproximation.residues Method
residues(r)
Returns two vectors of the poles and residues of the rational function r
.
RationalFunctionApproximation.rewind Method
rewind(r, index)
Rewind a rational approximation to a state encountered during an iteration.
Arguments
r::Approximation}
: the approximation to rewindindex::Integer
: the iteration number to rewind to
Returns
- the rational function of the specified index (same type as input)
Examples
julia> r = approximate(x -> cos(20x), unit_interval)
Barycentric{Float64, Float64} rational interpolant of type (24, 24) on the domain: Path{Float64} with 1 curve
julia> rewind(r, 10)
Barycentric{Float64, Float64} rational interpolant of type (10, 10) on the domain: Path{Float64} with 1 curve
RationalFunctionApproximation.roots Method
roots(r)
Return the roots (zeros) of the rational function r
.
RationalFunctionApproximation.roots Method
roots(r) returns the roots of the rational interpolant r
.