Functions and types
RationalFunctionApproximation.Approximation
RationalFunctionApproximation.Barycentric
RationalFunctionApproximation.Barycentric
RationalFunctionApproximation.ConvergenceStats
Base.values
RationalFunctionApproximation.aaa
RationalFunctionApproximation.approximate
RationalFunctionApproximation.check
RationalFunctionApproximation.decompose
RationalFunctionApproximation.degree
RationalFunctionApproximation.minimax
RationalFunctionApproximation.nodes
RationalFunctionApproximation.poles
RationalFunctionApproximation.residues
RationalFunctionApproximation.rewind
RationalFunctionApproximation.roots
RationalFunctionApproximation.stats
RationalFunctionApproximation.weights
RationalFunctionApproximation.Approximation
— TypeApproximation (type)
Approximation of a function on a domain.
Fields
original
: the original functiondomain
: the domain of the approximationfun
: the barycentric representation of the approximationprenodes
: the prenodes of the approximation
RationalFunctionApproximation.Barycentric
— TypeBarycentric (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
— TypeBarycentric(node, value, weight, wf=value.*weight; stats=missing)
Construct a Barycentric
rational function.
Arguments
node::AbstractVector
: interpolation nodesvalue::AbstractVector
: values at the interpolation nodesweight::AbstractVector
: barycentric weightswf::AbstractVector
: weights times values (optional)stats::ConvergenceStatistics
`: convergence statistics (optional)
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.ConvergenceStats
— TypeConvergenceStats{T}(bestidx, error, nbad, nodes, values, weights, poles)
Convergence statistics for a sequence of rational approximations.
Fields
bestidx
: the index of the best approximationerror
: the error of each approximationnbad
: the number of bad nodes in each approximationnodes
: the nodes of each approximationvalues
: the values of each approximationweights
: the weights of each approximationpoles
: the poles of each approximation
See also: approximate
, Barycentric
Base.values
— Methodvalues(r) returns the nodal values of the rational interpolant r
as a vector.
RationalFunctionApproximation.aaa
— Methodaaa(z, y)
aaa(f)
Adaptively compute a rational interpolant.
Arguments
discrete mode
z::AbstractVector{<:Number}
: interpolation nodesy::AbstractVector{<:Number}
: values at 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 stoppinglookahead::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.approximate
— Methodapproximate(f, domain)
Adaptively compute a rational interpolant on a curve, path, or region.
Arguments
f::Function
: function to approximatedomain
: curve, path, or region from ComplexRegions
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)
: relative tolerance for stoppingisbad::Function
: function to determine if a pole is badrefinement::Integer=3
: number of test points between adjacent nodeslookahead::Integer=10
: number of iterations to determine stagnationstats::Bool=false
: whether to return convergence statistics with the approximation (slower)
Returns
r::Approximation
: the rational interpolant
See also Approximation
, check
, aaa
.
Examples
julia> f(x) = tanh( 40*(x - 0.15) );
julia> r = approximate(f, unit_interval)
Barycentric rational function of type (22,22) on the domain: Path with 1 curve
julia> ( r(0.3), f(0.3) )
(0.9999877116507944, 0.9999877116507956)
julia> check(r); # accuracy over the domain
[ Info: Max error is 7.09e-14
RationalFunctionApproximation.check
— Methodcheck(r)
Check the accuracy of a rational approximation r
on its domain.
Arguments
r::Approximation
: rational approximation
Returns
τ::Vector
: test pointserr::Vector
: error at test points
See also approximate
, aaa
.
RationalFunctionApproximation.decompose
— Methoddecompose(r)
Return the roots, poles, and residues of the rational function r
.
RationalFunctionApproximation.degree
— Methoddegree(r) returns the degree of the numerator and denominator of the rational r
.
RationalFunctionApproximation.minimax
— Functionminimax(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
— Methodnodes(r) returns the nodes of the rational interpolant r
as a vector.
RationalFunctionApproximation.poles
— Methodpoles(r)
Return the poles of the rational function r
.
RationalFunctionApproximation.residues
— Methodresidues(r)
residues(r, p=poles(r))
Return the residues of the rational function r
. If a vector p
of poles is given, the residues are computed at those locations, preserving order.
RationalFunctionApproximation.rewind
— Methodrewind(r, degree)
Rewind a Barycentric
rational function to a lower degree using stored convergence data.
Arguments
r::Union{Barycentric,Approximation}
: the rational function to rewinddegree::Integer
: the degree to rewind to
Returns
- the rational function of the specified degree (same type as input)
Examples
julia> r = aaa(x -> cos(20x), stats=true)
Barycentric function with 25 nodes and values:
-1.0=>0.408082, -0.978022=>0.757786, -0.912088=>0.820908, … 1.0=>0.408082
julia> rewind(r, 10)
Barycentric function with 11 nodes and values:
-1.0=>0.408082, 1.0=>0.408082, -0.466667=>-0.995822, … 0.898413=>0.636147
RationalFunctionApproximation.roots
— Methodroots(r)
Return the roots (zeros) of the rational function r
.
RationalFunctionApproximation.stats
— Methodstats(r) returns the convergence statistics of the rational interpolant r
.
RationalFunctionApproximation.weights
— Methodweights(r) returns the weights of the rational interpolant r
as a vector.