Skip to content

Functions and types

RationalFunctionApproximation.Approximation Type
julia
Approximation (type)

Approximation of a function on a domain.

Fields

  • original: the original function

  • domain: the domain of the approximation

  • fun: the barycentric representation of the approximation

  • allowed: function to determine if a pole is allowed

  • prenodes: the prenodes of the approximation

  • test_points: test points where residual was computed

  • history: all approximations in the iteration

source
RationalFunctionApproximation.Barycentric Type
julia
Barycentric (type)

Barycentric representation of a rational function.

Fields

  • node: the nodes of the rational function

  • value: the values of the rational function

  • weight: the weights of the rational function

  • wf: the weighted values of the rational function

  • stats: convergence statistics

source
RationalFunctionApproximation.Barycentric Type
julia
Barycentric(node, value, weight, wf=value .* weight; stats=missing)

Construct a Barycentric rational function.

Arguments

  • node::Vector: interpolation nodes

  • value::Vector: values at the interpolation nodes

  • weight::Vector: barycentric weights

Keywords

  • wf::Vector = value .* weight: weights times values

Returns

  • ::Barycentric: a barycentric rational interpolating function

Examples

julia
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
source
RationalFunctionApproximation.DiscretizedPath Method
julia
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 ComplexPath

  • s: a vector of parameter values

  • n: number of points to discretize the path

Keyword arguments

  • refinement: number of refinements to make between consecutive points

  • maxpoints: maximum number of points ever allowed

See also collect, add_node!.

source
RationalFunctionApproximation.RFIVector Type

Sequence of rational interpolants produced by an iteration.

Fields

  • nodes: vector of interpolation nodes

  • values: vector of interpolation values

  • weights: matrix of all weights (upper triangle)

  • len: the number of nodes for each approximation

  • best: the index of the best approximation

See also: approximate

source
Base.collect Function
julia
collect(d::DiscretizedPath, which=:nodes)

Collect the points and parameters of a discretized path.

Arguments

  • d: a DiscretizedPath object

  • which: 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.

source
Base.values Method

values(r) returns a vector of the nodal values of the rational interpolant r.

source
RationalFunctionApproximation.Res Method
julia
Res(r, z)

Returns the residue of the rational function r at the point z.

source
RationalFunctionApproximation.aaa Method
julia
aaa(y, z)
aaa(f)

Adaptively compute a rational interpolant.

Arguments

discrete mode

  • y::AbstractVector{<:Number}: values at nodes

  • z::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 use

  • float_type::Type=Float64: floating point type to use for the computation

  • tol::Real=1000*eps(float_type): tolerance for stopping

  • stagnation::Integer=10: number of iterations to determines stagnation

  • stats::Bool=false: return convergence statistics

Returns

  • r::Barycentric: the rational interpolant

  • stats::NamedTuple: convergence statistics, if keyword stats=true

Examples

julia
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.

source
RationalFunctionApproximation.add_node! Method
julia
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 object

  • idx: a 2-element tuple, vector, or CartesianIndex into the params field. This identifies

the point to be promoted to a node.

Returns

  • A 2-element vector of CartesianIndices into the params and points fields.

See also DiscretizedPath, collect.

source
RationalFunctionApproximation.approximate Method
julia
approximate(f, domain)

Adaptively compute a rational interpolant on a continuous or discrete domain.

Arguments

Continuous domain

  • f::Function: function to approximate

  • domain: curve, path, or region from ComplexRegions

Discrete domain

  • f::Function: function to approximate

  • z::AbstractVector: point set on which to approximate

Keywords

  • max_iter::Integer=150: maximum number of iterations on node addition

  • float_type::Type: floating point type to use for the computation¹

  • tol::Real=1000*eps(float_type): relative tolerance for stopping

  • allowed::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
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
source
RationalFunctionApproximation.check Method
julia
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 output

  • prenodes::Bool=false: return prenodes of the approximation as well

Returns

  • τ::Vector: test points

  • err::Vector: error at test points

See also approximate.

source
RationalFunctionApproximation.convergenceplot Method
julia
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.

source
RationalFunctionApproximation.decompose Method
julia
decompose(r)

Return the roots, poles, and residues of the rational interpolant r.

source
RationalFunctionApproximation.degree Method

degree(r) returns the degree of the denominator of the rational r.

source
RationalFunctionApproximation.degrees Method

degrees(r) returns the degrees of the numerator and denominator of the rational r.

source
RationalFunctionApproximation.errorplot Method
julia
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.

source
RationalFunctionApproximation.get_history Method
julia
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.

source
RationalFunctionApproximation.minimax Function
julia
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
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>= minimax(r);

julia> check(r̂);
[ Info: Max error is 1.40e-03
source
RationalFunctionApproximation.nodes Method

nodes(r) returns a vector of the interpolation nodes of the rational interpolant.

source
RationalFunctionApproximation.poleplot Method
julia
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.

source
RationalFunctionApproximation.poles Method

poles(r) returns the poles of the rational interpolant r.

source
RationalFunctionApproximation.poles Method
julia
poles(r)

Return the poles of the rational function r.

source
RationalFunctionApproximation.residues Method
julia
residues(r)

Returns two vectors of the poles and residues of the rational function r.

source
RationalFunctionApproximation.rewind Method
julia
rewind(r, index)

Rewind a rational approximation to a state encountered during an iteration.

Arguments

  • r::Approximation}: the approximation to rewind

  • index::Integer: the iteration number to rewind to

Returns

  • the rational function of the specified index (same type as input)

Examples

julia
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
source
RationalFunctionApproximation.roots Method
julia
roots(r)

Return the roots (zeros) of the rational function r.

source
RationalFunctionApproximation.roots Method

roots(r) returns the roots of the rational interpolant r.

source