Functions and types

RationalFunctionApproximation.ApproximationType
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
  • prenodes: the prenodes of the approximation
source
RationalFunctionApproximation.BarycentricType
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.BarycentricType
Barycentric(node, value, weight, wf=value.*weight; stats=missing)

Construct a Barycentric rational function.

Arguments

  • node::AbstractVector: interpolation nodes
  • value::AbstractVector: values at the interpolation nodes
  • weight::AbstractVector: barycentric weights
  • wf::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
source
RationalFunctionApproximation.ConvergenceStatsType
ConvergenceStats{T}(bestidx, error, nbad, nodes, values, weights, poles)

Convergence statistics for a sequence of rational approximations.

Fields

  • bestidx: the index of the best approximation
  • error: the error of each approximation
  • nbad: the number of bad nodes in each approximation
  • nodes: the nodes of each approximation
  • values: the values of each approximation
  • weights: the weights of each approximation
  • poles: the poles of each approximation

See also: approximate, Barycentric

source
Base.valuesMethod

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

source
RationalFunctionApproximation.aaaMethod
aaa(z, y)
aaa(f)

Adaptively compute a rational interpolant.

Arguments

discrete mode

  • z::AbstractVector{<:Number}: interpolation nodes
  • y::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 use
  • float_type::Type=Float64: floating point type to use for the computation
  • tol::Real=1000*eps(float_type): tolerance for stopping
  • lookahead::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> 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.approximateMethod
approximate(f, domain)

Adaptively compute a rational interpolant on a curve, path, or region.

Arguments

  • f::Function: function to approximate
  • domain: curve, path, or region from ComplexRegions

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): relative tolerance for stopping
  • isbad::Function: function to determine if a pole is bad
  • refinement::Integer=3: number of test points between adjacent nodes
  • lookahead::Integer=10: number of iterations to determine stagnation
  • stats::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
source
RationalFunctionApproximation.minimaxFunction
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
source
RationalFunctionApproximation.residuesMethod
residues(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.

source
RationalFunctionApproximation.rewindMethod
rewind(r, degree)

Rewind a Barycentric rational function to a lower degree using stored convergence data.

Arguments

  • r::Union{Barycentric,Approximation}: the rational function to rewind
  • degree::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
source