Popularity
537 Stars
Updated Last
2 Months Ago
Started In
July 2013

ApproxFun.jl

CI codecov deps version pkgeval Aqua QA Join the chat at https://gitter.im/JuliaApproximation/ApproxFun.jl

ApproxFun is a package for approximating functions. It is in a similar vein to the Matlab package Chebfun and the Mathematica package RHPackage.

The ApproxFun Documentation contains detailed information, or read on for a brief overview of the package. The documentation contains examples of usage, such as solving ordinary and partial differential equations.

The ApproxFun Examples repo contains many examples of using this package, in Jupyter notebooks and Julia scripts. Note that this is independently maintained, so it might not always be in sync with the latest version of ApproxFun. We recommend checking the examples in the documentation first, as these will always be compatible with the latest version of the package.

Introduction

Approximating Functions

Take your two favourite functions on an interval and create approximations to them as simply as:

using LinearAlgebra, SpecialFunctions, Plots, ApproxFun
x = Fun(identity,0..10)
f = sin(x^2)
g = cos(x)

Evaluating f(.1) will return a high accuracy approximation to sin(0.01). All the algebraic manipulations of functions are supported and more. For example, we can add f and g^2 together and compute the roots and extrema:

h = f + g^2
r = roots(h)
rp = roots(h')

plot(h; label="f + g^2")
scatter!(r, h.(r); label="roots")
scatter!(rp, h.(rp); label="extrema")

Differentiation and integration

Notice from above that to find the extrema, we used ' overridden for the differentiate function. Several other Julia base functions are overridden for the purposes of calculus. We may check that the exponential is its own derivative, by evaluating the norm of the difference and checking that it is small:

f = Fun(exp, -1..1)
norm(f-f')  # 4.4391656415701095e-14

Similarly, cumsum defines an indefinite integration operator:

g = cumsum(f)
g = g + f(-1)
norm(f-g) # 3.4989733283850415e-15d

Algebraic and differential operations are also implemented where possible, and most of Julia's built-in functions (and special functions from SpecialFunctions.jl) are overridden to accept Funs:

x = Fun()
f = erf(x)
g = besselj(3,exp(f))
h = airyai(10asin(f)+2g)

Examples of Usage

Check the documentation for examples of usage.

References

J. L. Aurentz & R. M. Slevinsky (2019), On symmetrizing the ultraspherical spectral method for self-adjoint problems, arxiv:1903.08538

S. Olver & A. Townsend (2014), A practical framework for infinite-dimensional linear algebra, Proceedings of the 1st First Workshop for High Performance Technical Computing in Dynamic Languages, 57โ€“62

A. Townsend & S. Olver (2014), The automatic solution of partial differential equations using a global spectral method, J. Comp. Phys., 299: 106โ€“123

S. Olver & A. Townsend (2013), Fast inverse transform sampling in one and two dimensions, arXiv:1307.1223

S. Olver & A. Townsend (2013), A fast and well-conditioned spectral method, SIAM Review, 55:462โ€“489