Functions and types
RationalFunctionApproximation.ApproximationRationalFunctionApproximation.ArnoldiBasisRationalFunctionApproximation.ArnoldiPolynomialRationalFunctionApproximation.ArnoldiPolynomialRationalFunctionApproximation.BarycentricRationalFunctionApproximation.BarycentricRationalFunctionApproximation.BarycentricRationalFunctionApproximation.DiscretizedPathRationalFunctionApproximation.PartialFractionsBase.:\Base.collectBase.valuesRationalFunctionApproximation.ResRationalFunctionApproximation.aaaRationalFunctionApproximation.add_node!RationalFunctionApproximation.approximateRationalFunctionApproximation.approximateRationalFunctionApproximation.checkRationalFunctionApproximation.convergenceplotRationalFunctionApproximation.degreeRationalFunctionApproximation.degreesRationalFunctionApproximation.derivativeRationalFunctionApproximation.errorplotRationalFunctionApproximation.get_historyRationalFunctionApproximation.minimaxRationalFunctionApproximation.nodesRationalFunctionApproximation.poleplotRationalFunctionApproximation.polesRationalFunctionApproximation.polesRationalFunctionApproximation.residuesRationalFunctionApproximation.rewindRationalFunctionApproximation.rootsRationalFunctionApproximation.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 allowedpath: aDiscretizedPathfor the domain boundaryhistory: all approximations in the iteration
RationalFunctionApproximation.ArnoldiBasis Type
ArnoldiBasis (type)Well-conditioned representation for polynomials on a discrete point set.
Fields
nodes: evaluation pointsQ: orthogonal basisH: orthogonalization coefficients
RationalFunctionApproximation.ArnoldiPolynomial Type
ArnoldiPolynomial (type)Polynomial representation using an ArnoldiBasis.
Fields
coeff: vector of coefficientsbasis: ArnoldiBasis for the polynomial
RationalFunctionApproximation.ArnoldiPolynomial Method
p(z)
evaluate(p, z)Evaluate the ArnoldiPolynomial p at z.
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.5RationalFunctionApproximation.Barycentric Method
r(z)
evaluate(r, z)Evaluate the rational function at z.
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.PartialFractions Type
PartialFractions (type)Well-conditioned representation for polynomials on a discrete point set.
Fields
polynomial::ArnoldiPolynomial: analytic partpoles::Vector: polesresidues::Vector: residues (i.e., coefficients of the partial fractions)
Base.:\ Method
\(B::ArnoldiBasis, f::Function)Find the least-squares projection of f onto the B, returning an ArnoldiPolynomial.
Example
julia> z = point(Circle(0, 1), range(0, 1, 800));
julia> B = ArnoldiBasis(z, 10);
julia> p = B \ cos
Arnoldi polynomial of degree 10
julia> maximum(abs, p.(z) - cos.(z))
2.780564247091573e-7Base.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.0000000000000002imSee 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, orCartesianIndexinto theparamsfield. This identifies
the point to be promoted to a node.
Returns
- A 2-element vector of
CartesianIndicesinto theparamsandpointsfields.
See also DiscretizedPath, collect.
RationalFunctionApproximation.approximate Method
approximate(f, domain, poles)Computes a linear least-squares approximation with prescribed poles.
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
degree: degree of the polynomial part of the approximant (defaults to length(poles) ÷ 2)init: initial number of nodes on the path (continuum only)refinement: number of test points between adjacent nodes (continuum only)
Returns
r::Approximation: the rational approximant
See also Approximation, check, rewind.
Examples
julia> f = tanh;
julia> ζ = 1im*[-π/2, π/2];
julia> r = approximate(f, unit_interval, ζ; degree=10)
PartialFractions{ComplexF64} rational function of type (12, 2) on the domain: Segment(-1.0,1.0)
julia> ( r(0.3), f(0.3) )
(0.2913126124509021 + 1.1102230246251565e-16im, 0.2913126124515909)
julia> check(r); # accuracy over the domain
[ Info: Max error is 2.75e-12RationalFunctionApproximation.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=5: 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-13RationalFunctionApproximation.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.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.derivative Method
derivative(r::Approximation)Create an approximation of the derivative of r on the same domain.
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-03RationalFunctionApproximation.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 curveRationalFunctionApproximation.roots Method
roots(r)Return the roots (zeros) of the rational function r.
RationalFunctionApproximation.roots Method
roots(r) returns the roots of the rational function r.