Math 660-Lecture 15: Spectral methods: Fourier pseduo-spectral method

The topics here will be in the book ‘Spectral methods in Matlab’ (Chap- ter 3); Another reference book is ‘Spectral methods in chemistry and physics.’

1 Spectral methods v.s. pseudo-spectral methods

1.1 Spectral method A spectral method is to represent the solution of a differential equation in terms of a basis of some vector space and then reduce the differential equations to an ODE system for the coefficients. In this sense, the (contin- uous) Fourier Transform and the Finite Element methods are all spectral methods. In particular, suppose we have some equation

T (u) = f(x) where T is some temporal-spatial operator for the differential equation. Then, under the basis we have the error: X X R(x) = T ( ci(t)φi(x)) − f˜iφi i i

Pick test functions {χj}, which is the dual basis of {φi(x)} (if the space is a like in FEM, these two are identical) and we require

hχj,Ri = 0.

This then gives a system of equations for cj.

• Advantages: Reduce differential operators to multiplications, and solv- ing ODEs might be easier. • Disadvatange: The multiplication in the spatial variable becomes con- volution. Then, we may have a big matrix-vector multiplication.

1.2 Pseudo-spectral method Here, represent the solution in terms of the basis but impose the equa- tion only at discrete points. As we can see, the pseudo-spectral method in some sense is a spectral method in discrete space. There are some typical pseudo-spectral methods

1 • Fourier Pseudo-spectral method with trigonometric basis

• Chebyshev pseudo-spectral method with Chebyshev polynomial basis

• Collocation methods with polynomial basis (especially for ODEs solvers); (Some people also call the pseudo-spectral method the .)

For discrete points, we often choose χj = δ(x − xj), so that we require

R(xj) = 0.

The pseudo-spectral method may have efficient algorithms, which makes solving PDEs fast. For example, to compute a(x)ux(x, t), using spectral method where x is continuous, we have an infinite . Even if we truncate, we have a matrix multiplied with a vector. However, if we use the Fourier pseudo-spectral method, we can make use of the FFT and IFFT to change the function back into x space and perform the multiplication in x space. This will save a lot of time. In this course, we will only cover Fourier pseudo-spectral method. You can read the Chebyshev yourself, which is also useful.

2 Basic theories for Discrete Fourier Transform (DFT)

Consider N (an even number) points v1, v2, . . . , vN . We define the DFT as N X −ikxn vˆk = e vn, k ∈ Z n=1 2π where xn = N n. This means that we regard v as a function on (0, 2π] and xn is a sample point on the interval.

• Note that the definition here is a little different from the book. We use this because it’s more common. Also in Matlab, the summation is PN −ikxn−1 n=1 e vn, which will not cause a trouble, since we can imagine that we are doing a shifted sequence or vn is associated with xn−1 instead of xn.

PN−1 −ikxn • Other people also use the definition as n=0 e vn. Of course, this is equivalent to ours if we regard xN as x0.

2 • Different definitions (shifting the sequence) may result in a uniform factor phase for the DFT. However, as long as we have consistent inverse formula, it is just fine.

Properties

• vˆk =v ˆk+mN . In Matlab, the output is for k = 0, 1, 2,...,N − 1 or k = 0, 1, 2,...,N/2, −N/2 + 1,..., −1. In other words, fft(v) gives a vector w such that w(1) =v ˆ0, . . . , w(N) =v ˆN−1. ¯ • If v is real valued, thenv ˆk = vˆ−k, where the bar means complex conjugate. If follows thatv ˆN/2 is real. • Define the discrete convolution:

N X wn = (u ∗ v)n = ujvn−j j=1

where vn−j = vN+n−j if n − j < 0. Then,

wˆk =u ˆkvˆk.

• The discrete Parseval equality holds:

N/2 X 1 X u v = uˆ vˆ n n N k k n k=−N/2+1

Let us prove the last two.

Proof. For the discrete convolution, we have

N N N N X −ikxn X X −ikxj X −ik(xn−xj ) wˆk = e ujvn−j = uje e vn−j n=1 j=1 j=1 n=1 By the cyclic symmetry, we have the result. We have

N/2 X X X −ikxm X ikxn X X ik(xn−xm) uˆkvˆk = ( ume )( vne ) = umvn e k=−N/2+1 k m n m,n k P The sum on the right hand side is Nδm,n, so we have N n unvn.

3 Remark 1. Some people want to define

N 1 X vˆ = e−ikxn v , k N n n=1 then the Parseval is

N/2 2π X X ( ) u v = 2π uˆ vˆ N n n k k n k=−N/2+1

Inverse DFT The inverse DFT is given by

N−1 N/2 1 X 1 X v = eikxn vˆ = eikxn vˆ . n N k N k k=0 k=−N/2+1

1 PN−1 ikxn−1 (In Matlab convention, we should have vn = N k=0 e vˆk, as vn is associated with xn−1.)

Proof. First of all, e−ik(xn−xj ) = e−ikxn−j ,

X X −ikxn X X −ikxn wˆk = ujvn−je = uj vn−je n j j n

X −ikxj X −ikxn−j X −ikxj = uje vn−je = uje vˆk =u ˆkvˆk. j n j

For the second,

N−1 N−1 1 X 1 X X 1 X X eikxn vˆ = eikxn v e−ikxm = v eik(xn−xm) N k N m N m k=0 k=0 m m k

P ik(xn−xm) P ik(n−m)h Clearly, k e = k e . If n = m, the sum is N. If n 6= m, the sum equals zero by the geometric sum since [eik(n−m)h]N = 1. Hence,

1 X X 1 X v eik(xn−xm) = v Nδ = v . N m N m n−m n m k m

4 3 FFT: fast algorithms to compute DFT

The most frequently used one is the Cooley-Tukey algorithm (the algo- rithm was independently discovered also by Gauss). The idea is based on the simple fact. Let N be even, then

N N/2 N/2 X −ikn 2π X −ikm 2π ik 2π X −ikm 2π une N = u2me (N/2) + e N u2m−1e (N/2) n=1 m=1 m=1 The DFT of an array of size N is reduced to 2 DFT of arrays with size N/2 plus extra N operations. By this way, the whole complexity is O(N log N).

4 Fourier Differentiation

For general x, we can define a function

N/2 1 X f(x) = eikxvˆ , N k k=−N/2+1

(m) (m) and then we use f (xj) to approximate the derivatives v (xj).

4.1 Algorithm for Fourier differentiation The above idea generates the following Fourier differentiation:

• Given v = (v1, . . . , vN ), computev ˆ.

m • Definew ˆk = (ik) vˆk, for k = −N/2+1,...,N/2 (or k = 0,...,N/2, −N/2+ 1,..., −1 in Matlab.)

• Compute the inverse DFT (inverse FFT) and get wk, the real part of which is the approximation of the derivative. we take real part because numerical error may introduce some complex val- ues.

Corollary 1. For the Fourier differentiation, without taking the real part, the discrete by Fourier differentiation holds.

This is a corollary of the Paserval equality. 1 PN−1 ikx Exercise: Will it matter if we use f(x) = N k=0 e vˆk to compute the derivatives? If it matters, which one is better? Choose a periodic smooth

5 function and code up to check out. Can you explain this? (Hint: Use the Aliasing formula in the next lecture.) However, the k = N/2 mode is a little bit strange. Assume v is a real array. Then, vˆN/2 = vˆ−N/2 = vˆN/2.

This meansv ˆN/2 is real. This mode will contribute derivative

iN i N x vˆ e 2 j N/2 2 Clearly, this part is imaginary at the given grid points.

6