Skip to content

Commit 50fbf3f

Browse files
authored
Modernize documentation (#759)
* Modernize documentation * Correct the equation in Boundary conditions section * Correct the equation in Systems of equations section * Put spaces in code more consistently * Do not put space around .. * Fix example in Nonlinear equations * Fix error in multivariate example code
1 parent fef0c7f commit 50fbf3f

File tree

7 files changed

+477
-873
lines changed

7 files changed

+477
-873
lines changed

docs/src/faq.md

Lines changed: 47 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
```@setup using-pkgs
2+
using ApproxFun, Random
3+
```
4+
15
# Frequently Asked Questions
26

37
## Approximating functions
@@ -6,108 +10,59 @@
610

711
In the case where the grid is specified by `points(space,n)`, you can apply the default transform to data:
812

9-
```@meta
10-
DocTestSetup = quote
11-
using ApproxFun
12-
end
13-
```
14-
15-
```jldoctest
16-
julia> S = Chebyshev(1..2);
17-
18-
julia> p = points(S,20); # the default grid
19-
20-
julia> v = exp.(p); # values at the default grid
21-
22-
julia> f = Fun(S,ApproxFun.transform(S,v));
23-
24-
julia> f(1.1)
25-
3.0041660239464347
26-
27-
julia> exp(1.1)
28-
3.0041660239464334
13+
```@repl using-pkgs
14+
S = Chebyshev(1..2);
15+
p = points(S,20); # the default grid
16+
v = exp.(p); # values at the default grid
17+
f = Fun(S,ApproxFun.transform(S,v));
18+
f(1.1)
19+
exp(1.1)
2920
```
3021

3122
ApproxFun has no inbuilt support for interpolating functions at other sets of points, but this can be accomplished manually by evaluating the basis at the set of points and using \:
3223

33-
```jldoctest
34-
julia> S = Chebyshev(1..2);
35-
36-
julia> n = 50;
37-
38-
julia> p = range(1,stop=2,length=n); # a non-default grid
39-
40-
julia> v = exp.(p); # values at the non-default grid
41-
42-
julia> V = Array{Float64}(undef,n,n); # Create a Vandermonde matrix by evaluating the basis at the grid
43-
44-
julia> for k = 1:n
45-
V[:,k] = Fun(S,[zeros(k-1);1]).(p)
46-
end
47-
48-
julia> f = Fun(S,V\v);
49-
50-
julia> f(1.1)
51-
3.0041660228311926
52-
53-
julia> exp(1.1)
54-
3.0041660239464334
24+
```@repl using-pkgs
25+
S = Chebyshev(1..2);
26+
n = 50;
27+
p = range(1,stop=2,length=n); # a non-default grid
28+
v = exp.(p); # values at the non-default grid
29+
V = Array{Float64}(undef,n,n); # Create a Vandermonde matrix by evaluating the basis at the grid
30+
for k = 1:n
31+
V[:,k] = Fun(S,[zeros(k-1);1]).(p)
32+
end
33+
f = Fun(S,V\v);
34+
f(1.1)
35+
exp(1.1)
5536
```
5637

5738
Note that an evenly spaced grid suffers from instability for large `n`. The easiest way around this is to use least squares with more points than coefficients, instead of interpolation:
5839

59-
```jldoctest
60-
julia> S = Chebyshev(1..2);
61-
62-
julia> n = 100; m = 50;
63-
64-
julia> p = range(1,stop=2,length=n); # a non-default grid
65-
66-
julia> v = exp.(p); # values at the non-default grid
67-
68-
julia> V = Array{Float64}(undef,n,m); # Create a Vandermonde matrix by evaluating the basis at the grid
69-
70-
julia> for k = 1:m
71-
V[:,k] = Fun(S,[zeros(k-1);1]).(p)
72-
end
73-
74-
julia> f = Fun(S,V\v);
75-
76-
julia> f(1.1)
77-
3.004166023946434
78-
79-
julia> exp(1.1)
80-
3.0041660239464334
40+
```@repl using-pkgs
41+
S = Chebyshev(1..2);
42+
n = 100; m = 50;
43+
p = range(1,stop=2,length=n); # a non-default grid
44+
v = exp.(p); # values at the non-default grid
45+
V = Array{Float64}(undef,n,m); # Create a Vandermonde matrix by evaluating the basis at the grid
46+
for k = 1:m
47+
V[:,k] = Fun(S,[zeros(k-1);1]).(p)
48+
end
49+
f = Fun(S,V\v);
50+
f(1.1)
51+
exp(1.1)
8152
```
8253

8354
We can use this same approach for multivariate functions:
8455

85-
```jldoctest
86-
julia> S = Chebyshev(0..1)^2;
87-
88-
julia> n = 1000; m = 50;
89-
90-
julia> Random.seed!(0); x = rand(n); y = rand(n);
91-
92-
julia> v = exp.(x .* cos(y)); # values at the non-default grid
93-
94-
julia> V = Array{Float64}(undef,n,m); # Create a Vandermonde matrix by evaluating the basis at the grid
95-
96-
julia> for k = 1:m
97-
V[:,k] = Fun(S,[zeros(k-1);1]).(x,y)
98-
end
99-
100-
101-
julia> f = Fun(S,V\v);
102-
103-
julia> f(0.1,0.2)
104-
1.1029700685084018
105-
106-
julia> exp(0.1*cos(0.2))
107-
1.1029701284210731
108-
```
109-
110-
111-
```@meta
112-
DocTestSetup = nothing
56+
```@repl using-pkgs
57+
S = Chebyshev(0..1)^2;
58+
n = 1000; m = 50;
59+
Random.seed!(0); x = rand(n); y = rand(n);
60+
v = exp.(x .* cos.(y)); # values at the non-default grid
61+
V = Array{Float64}(undef,n,m); # Create a Vandermonde matrix by evaluating the basis at the grid
62+
for k = 1:m
63+
V[:,k] = Fun(S,[zeros(k-1);1]).(x,y)
64+
end
65+
f = Fun(S,V\v);
66+
f(0.1,0.2)
67+
exp(0.1*cos(0.2))
11368
```

docs/src/index.md

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,75 @@
1-
# ApproxFun.jl Documentation
2-
1+
```@setup using-pkgs
2+
using ApproxFun
3+
```
34

5+
# ApproxFun.jl Documentation
46

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

89
## Introduction
910

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
1212

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+
```
1416

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
1918

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

2525
The approximation by a `Fun` can be determined by a variety of methods:
2626

2727
(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])
3128

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)
3432
```
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)
4038
```
41-
determines that `f` can be approximated to roughly machine precision using
42-
14 coefficients. See [Constructors](usage/constructors.md) for more information.
4339

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

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

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)
5448
```
49+
5550
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
5951

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())
6256
```
6357

58+
```@repl ab
59+
ncoefficients(a*b)
60+
a(0.1)*b(0.1) - (a*b)(0.1)
61+
```
6462

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).
7264

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).
7366

7467
## Contents
7568

76-
77-
7869
```@contents
79-
Pages = ["usage/constructors.md",
80-
"usage/domains.md",
70+
Pages = ["usage/domains.md",
8171
"usage/spaces.md",
72+
"usage/constructors.md",
8273
"usage/operators.md",
8374
"usage/equations.md",
8475
"faq.md",

0 commit comments

Comments
 (0)