Skip to content

bilman/ApproxFun.jl

 
 

Repository files navigation

ApproxFun.jl

Build Status Build status codecov 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 ApproxFun Examples contains many examples of using this package, in Jupyter notebooks and Julia scripts.

Introduction

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. Because the exponential is its own derivative, the norm is small:

f = Fun(x->exp(x), -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 are overridden to accept Funs:

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

Solving ordinary differential equations