A fast and well-conditioned spectral method:The US method
Alex TownsendUniversity of Oxford
Leslie Fox Prize, 24th of June 2013
Partially based on: S. Olver & T., A fast and well-conditioned spectral method, toappear in SIAM Review, (2013).
Alex Townsend, University of Oxford 24th of June 2013 0/26
The problem
Problem: Solve linear ordinary differential equations (ODEs)
aN(x)dNu
dxN+ · · ·+ a1(x)
du
dx+ a0(x)u = f (x), x ∈ [−1, 1]
with K linear boundary conditions (Dirichlet, Neumann,∫ 1
−1 u = c , etc.)Assumptions:
a0, . . . , aN , f are continuous with bounded variation.
The leading term aN(x) is non-zero on the interval.
The solution exists and is unique.
Main philosophy: Replace a0, . . . , aN , f by polynomial approximations,and solve for a polynomial approximation for u. The spectral methodfinds the coefficients in a Chebyshev series in O(m2n) operations:
u(x) ≈n−1∑k=0
αkTk(x), Tk(x) = cos(k cos−1 x).
Alex Townsend, University of Oxford 24th of June 2013 1/26
Overview
Conventional wisdom
A comparison
First-order ODEs
Higher-order ODEs
Stability and convergence
Fast linear algebra
PDEs
Conclusion
−1 −0.5 0 0.5 1−4
−2
0
2
4
6
degree(u) = 51511
x
u(x
)
x
y
−1 −0.5 0 0.5 1−1
−0.5
0
0.5
1
Alex Townsend, University of Oxford 24th of June 2013 2/26
Quotes about spectral methods
“It is known that matrices generated by spectral methods canbe dense and ill-conditioned.” [Chen 2005]
“The idea behind spectral methods is to take this process tothe limit, at least in principle, and work with a differentiationformula of infinite order and infinite bandwidth, i.e., a densematrix.” [Trefethen 2000]
“The best advice is still this: use pseudospectral (collocation)methods instead of spectral (coefficient), and use Fourier seriesand Chebyshev polynomials in preference to more exoticfunctions.” [Boyd 2003]
The Ultraspherical spectral method (US method) can result in almostbanded, well-conditioned linear systems.
Alex Townsend, University of Oxford 24th of June 2013 3/26
Chebyshev spectral methods
u′′(x) + cos(x)u(x) = 0, u(±1) = 0.
Collocation Coefficients US method
Conditionnumber
0 50 100 150 20010
0
105
1010
0 50 100 150 20010
0
105
1010
0 50 100 150 2002
3
4
Density
Collocation Coefficient US methodMatrix structure Dense Banded from below Banded + rank-K
Condition number O(n2N) O(n2N) O(n2(D−1))Problem sizes n ≤ 5,000 n ≤ 5,000 n ≤ 70,000
Operation count O(n3) O(mn2) O(m2n)
Alex Townsend, University of Oxford 24th of June 2013 4/26
First-order differential equations
DifferentiationOperator
MultiplicationOperator
u′(x) + a(x)u(x) = f(x)
(D + SM[a]) u = Sf
D : T→ C(1)
M[a] : T→ T
S : T→ C(1)
−1.5 −1 −0.5 0 0.5 1 1.5−1.5
−1
−0.5
0
0.5
1
1.5
Jacobi with w(x)=(1−x)α(1+x)
β
α
β
Differ
entia
tion
Con
vers
ion
Hyperg
eom
etr
ic functions
Hypergeometric functions
Jacobi
UltrasphericalT
L
C(1)
Alex Townsend, University of Oxford 24th of June 2013 5/26
First-order operators
Differentiation operator: D : T→ C(1), [DLMF]
dTk
dx=
{kC
(1)k−1, k ≥ 1,
0, k = 0,D =
0 1
23
. . .
.
Conversion operator: S : T→ C(1), [DLMF]
Tk =
12
(C
(1)k − C
(1)k−2
), k ≥ 2,
12C
(1)1 , k = 1,
C(1)0 , k = 0,
S =
1 0 − 1
212 0 − 1
2
12 0
. . .
. . .. . .
.
Multiplication operator: M[a] : T→ T, [DLMF]
TjTk =1
2
(T|j−k| + Tj+k
), j , k ≥ 0.
Alex Townsend, University of Oxford 24th of June 2013 6/26
First-order multiplication operator
TjTk =1
2T|j−k| +
1
2Tj+k
M[a] =1
2
2a0 a1 a2 a3 . . .
a1 2a0 a1 a2. . .
a2 a1 2a0 a1. . .
a3 a2 a1 2a0. . .
.... . .
. . .. . .
. . .
︸ ︷︷ ︸
Toeplitz
+1
2
0 0 0 0 . . .
a1 a2 a3 a4 . ..
a2 a3 a4 a5 . ..
a3 a4 a5 a6 . ..
... . ..
. ..
. .. . . .
︸ ︷︷ ︸
Hankel + rank-1
Multiplication is not a dense operator in finite precision. It is m-banded:
a(x) =∞∑k=0
akTk(x) =m∑
k=0
akTk(x) +O(ε),
where ak are aliased Chebyshev coefficients.
Alex Townsend, University of Oxford 24th of June 2013 7/26
Imposing boundary conditions
Dirichlet: u(−1) = c :
B = (1,−1, 1,−1, . . . , ) , Tk(−1) = (−1)k .
Neumann: u′(1) = c :
B = (0, 1, 4, 9, . . . , ) , Tk(1) = k2.
Other conditions:∫ 1
−1 u = c , u(0) = c , or u(0) + u′(π/6) = c .
Imposing boundary conditions by boundary bordering:
u′(x)+a(x)u(x) = f ,
Bu = c ,
(B
D + SM[a]
)=
(cf
).
The finite section can be done exactly by projection Pn = (In , 0):(BPT
n
Pn−1DPTn + Pn−1SPT
n+mPn+mM[a]PTn
)=
(c
Pn−1f
).
Alex Townsend, University of Oxford 24th of June 2013 8/26
First-order examples
Example 1
u′(x) + x3u(x) = 100 sin(20,000x2), u(−1) = 0.
The exact solution is
u(x) = e−x4
4
(∫ x
−1100e
t4
4 sin(20,000t2)dt
).
−1 −0.5 0 0.5 1−0.2
0
0.2
0.4
0.6
0.8
1
1.2
x
u(x
)
degree(u) = 20391
time = 15.5s
N = ultraop(@(x,u) · · · );N.lbc = 0; u = N \ f;
Adaptively selects thediscretisation size.
Forms a chebfun object[Chebfun V4.2].
‖u − u‖∞ = 1.5× 10−15.
Alex Townsend, University of Oxford 24th of June 2013 9/26
First-order examples
Example 2
u′(x) +1
1 + 50,000x2u(x) = 0, u(−1) = 1.
The exact solution with a = 50,000 is
u(x) = exp
(− tan−1(
√ax) + tan−1(
√a)√
a
).
−1 −0.5 0 0.5 10.985
0.99
0.995
1
1.005
u(x
)
x
degree(u) = 5093
−1 −0.5 0 0.5 110
−20
10−15
10−10
10−5
x
Ab
so
lute
err
or
Old chebop
Preconditioned collocation
US method
Alex Townsend, University of Oxford 24th of June 2013 10/26
Higher-order linear ODEs
Higher-order diff operators: Dλ : T→ C(λ), [DLMF]
dC(λ)k
dx=
{2λC
(λ+1)k−1 , k ≥ 1,
0, k = 0,Dλ = 2λ−1(λ−1)!
λ times︷ ︸︸ ︷
0 · · · 0 λλ+ 1
. . .
.
Higher-order conversion operators: Sλ : C(λ) → C(λ+1), [DLMF]
C(λ)k =
λ
λ+k
(C
(λ+1)k − C
(λ+1)k−2
), k ≥ 2,
λλ+1
C(λ+1)1 , k = 1,
C(λ+1)0 , k = 0,
Sλ =
1 − λ
λ+2λ
λ+1− λ
λ+3. . .
. . .
.
Multiplication operators:
Mλ[a] : Cλ → Cλ,
M1[a] : C(1) → C(1),
M1[a] = Toeplitz + Hankel.
−0.5 0 0.5 1 1.5 2 2.5−0.5
0
0.5
1
1.5
2
2.5
Jacobi with w(x)=(1−x)α(1+x)
β
α
β
Differ
entia
tion
Con
vers
ion
Jacobi
UltrasphericalT
C(1)
C(2)
L
Alex Townsend, University of Oxford 24th of June 2013 11/26
Construction of ultraspherical multiplication operators
Mλ[a] : C(λ) → C(λ) represents multiplication with a(x) in C (λ). If
a(x) =m∑j=0
ajC(λ)j (x),
then it can be shown that Mλ[a] is m-banded with
(Mλ[a])j,k =k∑
s=max(0,k−j)
a2s+j−kcλs (k , 2s + j − k), j , k ≥ 0,
where (to prevent overflow issues) we have
cλs (j , k) =j + k + λ− 2s
j + k + λ− s×
s−1∏t=0
λ+ t
1 + t×
j−s−1∏t=0
λ+ t
1 + t
×s−1∏t=0
2λ+ j + k − 2s + t
λ+ j + k − 2s + t×
j−s−1∏t=0
k − s + 1 + t
k − s + λ+ t.
For efficiency, we use a recurence relation to generate cλs (j , k).Alex Townsend, University of Oxford 24th of June 2013 12/26
A high-order example
aN(x)dNu
dxN+ aN−1(x)
dN−1u
dxN−1 + · · ·+ a0(x)u = f (x), Bu = c,
(B
MN [aN ]DN + SN−1MN−1[a
N−1]DN−1 + · · ·+ SN−1 · · · S0M0[a0]
)=
(c
SN−1 · · · S0f
)
Example 3: High-order ODE
u(10)(x) + cosh(x)u(8)(x) + cos(x)u(2)(x) + x2u(x) = 0
u(±1) = 0, u′(±1) = 1, u(k)(±1) = 0, k = 2, 3, 4.
−1 −0.5 0 0.5 1−0.5
−0.4
−0.3
−0.2
−0.1
0
0.1
0.2
0.3
0.4
0.5
x
u(x
)
20 40 60 80 100 120 14010
−25
10−20
10−15
10−10
10−5
100
||u
n+
1−
un||
2
n
(∫ 1
−1(u(x) + u(−x))2
) 12
= 1.3× 10−14.
Alex Townsend, University of Oxford 24th of June 2013 13/26
Airy equation and regularity preserving
Example 4
Consider Airy’s equation for ε > 0,
εu′′(x)− xu(x) = 0, u(−1) = Ai(− 3√
1/ε), u(1) = Ai
(3√
1/ε).
0.5 1 1.5 2 2.5 3
x 104
100
102
104
106
108
1010
n
Conditio
n N
um
ber
ε = 1
ε = 10−4
ε = 10−9
0 50 100 150 200
10−15
10−10
10−5
100
105
n
Re
lative
err
or
Relative error in derivative at x=1/2
Ai(1)
Ai(20)
Ai(100)
The US method can accurately compute high derivatives of functions.For a different approach, see [Bornemann 2011].
Alex Townsend, University of Oxford 24th of June 2013 14/26
Stability when K = N
Assumption: Number of boundary conditions = Differential order.
Definition: Higher-order `2λ-norms
For λ ∈ N, `2λ ⊂ C∞ is the Banach space with norm
‖u‖2`2λ =∞∑k=0
|uk |2(1 + k)2λ <∞.
Right diagonal preconditioner:
R =1
2N−1(N − 1)!
IN
1N
1N+1 . . .
.
Alex Townsend, University of Oxford 24th of June 2013 15/26
Stability when K = N
Recall the notation:
Solve Lu = f ,
with Bu = c, B : `2D → CK ,bounded, D ≥ 1.
Theorem: Condition number is bounded with n
Let
(BL
): `2λ+1 → `2λ be an invertible operator for some λ ≥ D − 1.
Then, as n→∞,
‖AnRn‖`2λ = O(1), ‖(AnRn)−1‖`2λ = O(1),
where
Rn = PTn RPn, An = PT
n
(BL
)Pn.
Proof uses integral reformulation ideas: “R integrates the ODE toform a Fredholm operator”, i.e.,(
BL
)R = I +K, K = compact.
Alex Townsend, University of Oxford 24th of June 2013 16/26
Convergence with K = N
Theorem: Computed solution converges in high-order norms
Suppose f ∈ `2λ−N+1 for some λ ≥ D − 1, and that
(BL
): `2λ+1 → `2λ is
an invertible operator. Define
un = A−1n Pn
(c
SN−1 · · · S0f
),
then‖u− P>n un‖`2λ+1
≤ C‖u− P>n Pnu‖`2λ+1.
The constant, C , does notdepend on n.
You don’t always need thecomplex plane to computehigh derivatives.
0 50 100 150 200
10−15
10−10
10−5
100
105
n
Re
lative
err
or
Relative error in derivative at x=1/2
Ai(1)
Ai(20)
Ai(100)
Alex Townsend, University of Oxford 24th of June 2013 17/26
Fast linear algebra: The QTP∗ factorisation
Original matrix: After left Givens: After right Givens:
Apply a partial factorisation on the left, followed by a partialfactorisation on the right.
Factorisation: An = QTP∗ in O(m2n) operations.
No fill-in: The matrix T contains no more non-zeros than An.
For solving Anx = b: The matrix Q can be immediately applied to b.The matrix P∗ can be stored using Demmel’s trick [Demmel 1997].
UMFPACK by Davis is faster for n ≤ 50000, but has observedcomplexity of, roughly, O(n1.25) with a very small constant.
Alex Townsend, University of Oxford 24th of June 2013 18/26
Constant coefficient PDEs
Consider the constant coefficient PDE
N∑j=0
N−j∑i=0
aij∂ i+ju
∂ ix∂jy= f (x , y), aij ∈ R
defined on [a, b]× [c , d ] with linear boundary conditions satisfyingcontinuity conditions.We discretise as a generalised Sylvester matrix equation
k∑j=1
σjAjXBTj = F , Aj ∈ Rn1×n1 , Bj ∈ Rn2×n2 ,
where Aj and Bj are US discretisations, for example,
Aj =
( )Alex Townsend, University of Oxford 24th of June 2013 19/26
Determining the rank of a PDE operator
Given a PDE with constant coefficients of the form,
L =N∑j=0
N−j∑i=0
aij∂ i+j
∂ ix∂jy, A = (aij) .
We can rewrite this as
L = D(y)TAD(x), D(x) =
∂0/∂x0
...∂N/∂xN
.
Hence, if A = UΣV T is the truncated SVD of A with Σ ∈ Rk×k then
L = D(y)T(UΣV T
)D(x) =
(D(y)TU
)Σ(V TD(x)
).
This low rank representation for L tells us how to discretize and solve thePDE.
Alex Townsend, University of Oxford 24th of June 2013 20/26
Matrix equation solvers
Rank-1: A1XBT1 = F . Solve A1Y = F , then B1XT = Y T .
Rank-2: A1XBT1 + A2XBT
2 = F . Generalised Sylvester solver[Jonsson & Kagstrom, 1992].
Rank-k, k ≥ 3: Solve n1n2 × n1n2 system with QTP∗ factorization.
O(n1n2)
O(n31 + n32)O(n31n2)
n1 & n2
Boundary conditions areimposed by carefullyremoving degrees offreedom in the matrixequation.
Automatically forms andsolves subproblems, ifpossible.
Corner singularities can bepartly resolved by domainsubdivision.
Alex Townsend, University of Oxford 24th of June 2013 21/26
Examples
Example 5: Helmholtz equation
uxx + uyy + 2ω2u = 0, u(±1, y) = f (±1, y), u(x ,±1) = f (x ,±1),
where f (x , y) = cos(ωx) cos(ωy).
x
y
ω = 50
−1 −0.5 0 0.5 1−1
−0.5
0
0.5
1 N = chebop2(@(u) ... );
N.lbc=f(-1,:); u=N\0;Adaptively selects thediscretisation size.
Forms a chebfun2 object[T. & Trefethen 2013].
For ω = 2000,‖u − u‖2 = 2.43× 10−9.
For ω = 50 solve takes 0.27s for n1 = n2 = 126,for ω = 2000 solve takes 32.1s for n1 = n2 = 2124.
Alex Townsend, University of Oxford 24th of June 2013 22/26
Conclusions
The US method results in almost banded well-conditioned matrices.
It requires O(m2n) operations to solve an ODE.
It can be used as a preconditioner for the collocation method.
The US method converges and is numerically stable.
It can be extended to a spectral method for solving PDEs onrectangular domains.
Alex Townsend, University of Oxford 24th of June 2013 23/26
Historical example [Orszag 1971]
Orr-Sommerfeld equation
1
5772.2(u′′′′ − 2u′′ + u)− 2iu − i(1− x2)(u′′ − u) = λ(u′′ − u),
u(±1) = u′(±1) = 0.
−1 −0.8 −0.6 −0.4 −0.2 0−1
−0.9
−0.8
−0.7
−0.6
−0.5
−0.4
−0.3
real
ima
g
Eigenvalues of the Orr−Sommerfeld operator
Alex Townsend, University of Oxford 24th of June 2013 24/26
The end
Thank you
More information:S. Olver & T., A fast and well-conditioned spectral method, to appear inSIAM Review, (2013).
Alex Townsend, University of Oxford 24th of June 2013 25/26
References
F. Bornemann, Accuracy and stability of computing high-order derivatives ofanalytic functions by Cauchy integrals, Found. Comput. Math., 11 (2011),pp. 1–63.
I. Jonsson & Kagstrom, Recursive blocked algorithms for solving triangularmatrix equations — Part II: Two-sided and generalized Sylvester and Lyapunovequations, ACM Trans. Math. Softw., 28 (2002), pp. 416–435.
S. Olver & T., A fast and well-conditioned spectral method, to appear in SIAMReview, (2013).
S. Orszag, Accurate solution of the Orr-Sommerfeld stability equation, J. FluidMech., 50 (1971), pp. 689–703.
T. & L. N. Trefethen, An extension of Chebfun to two dimensions, likely toappear in SISC, (2013).
L. N. Trefethen et al., The Chebfun software system, version 4.2 , 2011.
Alex Townsend, University of Oxford 24th of June 2013 26/26
Chebyshev polynomials
An underappreciated fact: Every Chebyshev series can be rewritten asa palindromic Laurent series.
The degree k Chebyshev polynomial (of the first kind) is defined by
Tk(x) = cos(k cos−1 x
)=
1
2
(zk + z−k
), x ∈ [−1, 1],
where z = e ikθ and cos θ = x .
−1 −0.5 0 0.5 1−1
−0.5
0
0.5
1
T25
(x)
x0 1.5708 3.1416
−1
0
1
T25
(θ) = cos(25θ)
θ
Every Chebyshev series can be written as a palindromic Laurent series:
N∑k=0
αkTk(x) =1
2
N∑k=1
αkz−k + 1α0 +1
2
N∑k=1
αkzk , z = e ikθ.
Alex Townsend, University of Oxford 24th of June 2013 27/26
Demmel’s trick for storing Givens rotations
A Givens rotation zeros out one entry of a matrix and we can store therotation information there.
× × × ×× × × ×× � × ×× × × ×
Givens︷︸︸︷−→
× × × ×× × × ×× p × ×× × × ×
Let s = sin θ and c = cos θ, where θ is rotation angle, then
p =
{s · sign(c), |s| < |c |,sign(s)
c , |s| ≥ |c |.
To restore (up to a 180 degrees): If |p| < 1, then s = p andc =√
1− s2, otherwise c = 1/p and s =√
1− c2.
Alex Townsend, University of Oxford 24th of June 2013 28/26