|
1 | | -# ApproxFun.jl Documentation |
2 | | - |
| 1 | +```@setup using-pkgs |
| 2 | +using ApproxFun |
| 3 | +``` |
3 | 4 |
|
| 5 | +# ApproxFun.jl Documentation |
4 | 6 |
|
5 | | -ApproxFun is a package for approximating and manipulating functions, |
6 | | -and for solving differential and integral equations. |
| 7 | +ApproxFun is a package for approximating and manipulating functions, and for solving differential and integral equations. |
7 | 8 |
|
8 | 9 | ## Introduction |
9 | 10 |
|
10 | | -A basic approach of computational mathematics that ApproxFun exploits is expansion |
11 | | -in a basis |
| 11 | +A basic approach of computational mathematics that ApproxFun exploits is expansion in a basis |
12 | 12 |
|
13 | | -$$f(x) \approx \sum_{k=1}^n c_k \psi_k(x)$$ |
| 13 | +```math |
| 14 | +\mathop{f}(x) \approx \sum_{k=1}^n c_k \mathop{ψ}_k(x). |
| 15 | +``` |
14 | 16 |
|
15 | | -Some traditional examples of bases $\psi_1(x),\psi_2(x),\ldots$ are |
16 | | -1. Taylor series: $1,z,z^2,\ldots$ |
17 | | -2. Fourier series (for periodic functions on `0..2π`): $1,\sin x, \cos x, \sin 2 x, \ldots$ |
18 | | -3. Chebyshev series (for non-periodic functions on `-1..1`): $1,x,\cos 2 \hbox{acos}\, x, \cos 3 \hbox{acos}\, x, \ldots$ |
| 17 | +Some traditional examples of bases ``\mathop{ψ}_1(x), \mathop{ψ}_2(x), …`` are |
19 | 18 |
|
20 | | -In ApproxFun, functions are represented by a `Fun` with two components: `space`, |
21 | | -which dictates the basis and `coefficients` which is a finite vector of coefficients. Note that each `Fun` can have a different length vector of |
22 | | -coefficients, allowing for approximation of many different functions to high |
23 | | -accuracy. |
| 19 | +1. Taylor series: ``1, x, x^2, …`` |
| 20 | +2. Fourier series (for periodic functions on `0..2π`): ``1, \sin{x}, \cos{x}, \sin{2x}, …`` |
| 21 | +3. Chebyshev series (for non-periodic functions on `-1..1`): ``1, x, \cos(2\arccos{x}), \cos(3\arccos{x}), …`` |
| 22 | + |
| 23 | +In ApproxFun, functions are represented by a `Fun` with two components: `space`, which dictates the basis and `coefficients` which is a finite vector of coefficients. Note that each `Fun` can have a different length vector of coefficients, allowing for approximation of many different functions to high accuracy. |
24 | 24 |
|
25 | 25 | The approximation by a `Fun` can be determined by a variety of methods: |
26 | 26 |
|
27 | 27 | (1) Explicitly specifying the coefficients: |
28 | | -```julia |
29 | | -julia> f = Fun(Taylor(),[1,2,3]) # Represents 1 + 2z + 3z^2 |
30 | | -Fun(Taylor(🕒),[1.0,2.0,3.0]) |
31 | 28 |
|
32 | | -julia> f(1.0) |
33 | | -6.0 |
| 29 | +```@repl using-pkgs |
| 30 | +f = Fun(Taylor(),[1,2,3]) # Represents 1 + 2x + 3x^2 |
| 31 | +f(1.0) |
34 | 32 | ``` |
35 | | -(2) Constructors take in a `Function` and adaptively determine the |
36 | | - number of coefficients. For example, |
37 | | -```julia |
38 | | -julia> Fun(exp) |
39 | | -Fun(Chebyshev(【-1.0,1.0】),[1.26607,1.13032,0.271495,0.0443368,0.00547424,0.000542926,4.49773e-5,3.19844e-6,1.99212e-7,1.10368e-8,5.5059e-10,2.49797e-11,1.03911e-12,3.99195e-14]) |
| 33 | + |
| 34 | +(2) Constructors take in a `Function` and adaptively determine the number of coefficients. For example, |
| 35 | + |
| 36 | +```@repl using-pkgs |
| 37 | +Fun(exp) |
40 | 38 | ``` |
41 | | -determines that `f` can be approximated to roughly machine precision using |
42 | | -14 coefficients. See [Constructors](usage/constructors.md) for more information. |
43 | 39 |
|
44 | | -(3) Manipulation of `Fun`s give new `Fun`s, where the number of coefficients is determined from the input. The simplest example is addition, which for compatible bases is just padding the vectors to the same length and adding. |
45 | | -```julia |
46 | | -julia> a = Fun(cos,Chebyshev()); ncoefficients(a) |
47 | | -13 |
| 40 | +determines that `f` can be approximated to roughly machine precision using 14 coefficients. See [Constructors](usage/constructors.md) for more information. |
48 | 41 |
|
49 | | -julia> b = Fun(x->cos(10cos(x^2)),Chebyshev()); ncoefficients(b) |
50 | | -51 |
| 42 | +(3) Manipulation of `Fun`s give new `Fun`s, where the number of coefficients is determined from the input. The simplest example is addition, which for compatible bases is just padding the vectors to the same length and adding. |
51 | 43 |
|
52 | | -julia> ncoefficients(a+b) |
53 | | -51 |
| 44 | +```@repl using-pkgs |
| 45 | +a = Fun(cos,Chebyshev()); ncoefficients(a) |
| 46 | +b = Fun(x->cos(10cos(x^2)),Chebyshev()); ncoefficients(b) |
| 47 | +ncoefficients(a+b) |
54 | 48 | ``` |
| 49 | + |
55 | 50 | On the other hand, multiplication results in an approximation with more coefficients than either `a` or `b`, so that the result approximates the true `a*b` to roughly machine accuracy: |
56 | | -``` |
57 | | -julia> ncoefficients(a*b) |
58 | | -63 |
59 | 51 |
|
60 | | -julia> a(0.1)*b(0.1) - (a*b)(0.1) |
61 | | -1.1102230246251565e-16 |
| 52 | +```@setup ab |
| 53 | +using ApproxFun |
| 54 | +a = Fun(cos,Chebyshev()) |
| 55 | +b = Fun(x->cos(10cos(x^2)),Chebyshev()) |
62 | 56 | ``` |
63 | 57 |
|
| 58 | +```@repl ab |
| 59 | +ncoefficients(a*b) |
| 60 | +a(0.1)*b(0.1) - (a*b)(0.1) |
| 61 | +``` |
64 | 62 |
|
65 | | -The example of multiplication highlights the importance of adaptivity: if with a fixed discretization size, operations like multiplication would lose accuracy when the true function is no longer resolved by the discretization. More complicated examples are solving differential equations, where the |
66 | | -coefficients of the solution can be determined adaptively, see [Equations](usage/equations.md). |
67 | | - |
68 | | - |
69 | | - |
70 | | -ApproxFun supports a number of different spaces, as described in [Spaces](usage/spaces.md). A key component of ApproxFun is support for interaction between different |
71 | | -spaces. This is crucial for efficient solution of differential equations, where linear operators are described as acting between different spaces, see [Operators](usage/operators.md). |
| 63 | +The example of multiplication highlights the importance of adaptivity: if with a fixed discretization size, operations like multiplication would lose accuracy when the true function is no longer resolved by the discretization. More complicated examples are solving differential equations, where the coefficients of the solution can be determined adaptively, see [Equations](usage/equations.md). |
72 | 64 |
|
| 65 | +ApproxFun supports a number of different spaces, as described in [Spaces](usage/spaces.md). A key component of ApproxFun is support for interaction between different spaces. This is crucial for efficient solution of differential equations, where linear operators are described as acting between different spaces, see [Operators](usage/operators.md). |
73 | 66 |
|
74 | 67 | ## Contents |
75 | 68 |
|
76 | | - |
77 | | - |
78 | 69 | ```@contents |
79 | | -Pages = ["usage/constructors.md", |
80 | | - "usage/domains.md", |
| 70 | +Pages = ["usage/domains.md", |
81 | 71 | "usage/spaces.md", |
| 72 | + "usage/constructors.md", |
82 | 73 | "usage/operators.md", |
83 | 74 | "usage/equations.md", |
84 | 75 | "faq.md", |
|
0 commit comments