considered in [3, 7, 131. The matrix D for the Chebyshev points (2.14) is given in. [7]. An alternative to using matrix multiplication is to find the derivative by using.
JOURNAL
OF COMPUTATlONAL
PHYSICS 81,
239-276 (1989)
Global Properties of Pseudospectral Methods A. SOLOMONOFF* ICOMP
NASA
Lewis
Research
Center,
Cleveland,
Ohio
AND
E. TURKEL' Institute
for Computer Applications in Science and Engineering, NASA Lewis Research Center, Cleveland, Ohio and Sackler Faculty of Exact Sciences, Tel-Aviv University, Tel-Aviv, Israel
Received January 16, 1987; revised March 16, 1988
We apply polynomial interpolation methods both to the approximation of functions and to the numerical solutions of hyperbolic and elliptic partial differential equations. The derivative matrix for a general sequence of collocation points is explicitly constructed. We explore the effect of several factors on the performance of these methods. We show that global methods cannot be interpreted’in terms of local methods. For example, the accuracy of the approximation differs when large gradients of the function occur near the center of the region or in the vicinity of the boundary. This difference does not depend on the density of the collocation points near the boundaries. Hence, intuition based on finite difference methods can lead to false results. 0 1989 Academic Press, Inc.
1. INTRODUCTION In this study we consider the accuracy of the pseudospectral algorithm both for approximating a function and also for the numerical solution of differential equations. We shall only consider collocation methods, but most of the results shown also apply to Galerkin methods. We approximate the function, f(x), by a polynomial, PN(x), that interpolates f(x) at N+ 1 distinct points x0, .... xN. f’(x) is approximated by P;(x), which is calculated analytically. In solving differential equations we use an approach similar to finite differences. Thus, all derivatives that appear are replaced by their pseudospectral approximation. The resulting system is * Present address: Brown University, Department of Applied Mathematics. + Research supported by NASA Contracts NASl-17070 and NASl-18107 while he was in residence at NASA Lewis Research Center, Cleveland, OH 44135 and ICASE, NASA Langley Research Center, Hampton, VA 23665.
239 0021-9991/89 $3.00 Copyright 0 1989 by Academic Press, Inc. All rigbts of reproduction in any form mserved.
240
SOLOMONOFF
AND
TURKEL
solved in space or advanced in time for time-dependent equations. Hence, for an explicit scheme, nonlinearities do not create any special difficulties. For a collocation method, the coefficients of the series are obtained by demanding that the approximation interpolate the function at the collocation points. This requires O(N’) operations. For special sequences of collocation points, e.g., Chebyshev nodes, this can be accomplished by using FFTs and requires only O(N log N) operations. Every collocation method has two interpretations: one in terms of interpolation at the collocation points and one in terms of a series expansion but with different coefficients than a Galerkin expansion. In the past, this has lead to some confusion. As an example we consider the case of a Chebyshev collocation method with xi= cos(rrj/N). From an approximation viewpoint, we know [ll, 15-181 that the maximum error for interpolation at the zeros of T,,,(x) is within a factor of (4 + 2/7c log N) of the minimax error and converges to zero as N-+ co for all functions in C’. The bound for the error based on the points xi, given above, is even smaller than this [13]. There also exist sharp estimates in Sobolev spaces [3]. Since the minimax approximation has an error which is equioscillatory, we expect the Chebyshev interpolant to be nearly equi-oscillatory. Indeed, Remez suggests using these xj as a first guess in finding the zeros off - P, in this algorithm for the minimax approximation. Thus, we would expect that when Chebyshev points are used to solve differential equations the error will be essentially uniform throughout the domain. On the other hand, considered as a finite difference type scheme with N+ 1 nodes, one expects the scheme to be more accurate near the boundaries where the collocation points are clustered. At the center of the domain the distance between points is approximately n/2N, while near the boundary the smallest distance between two points is approximately 7r2/2N2. Hence, the spacing at the center is about n/2 times coarser than an equivalent equally spaced mesh and near the boundary it is about 4N/7r2 times liner. Thus, one expects the accuracy and resolving power of the scheme to be better near the boundaries. However, the bunching of points near the boundaries only serves to counter the tendency of polynomials to oscillate with large amplitude near the boundary. We shall also consider collocation based on uniformly spaced points. Since we consider polynomial interpolation on the interval ( - 1, l), we get qualitatively different results than those obtained by Fourier or finite difference methods even for the same collocation points. In fact, we shall see that the boundaries exert a strong influence in this case just as with Chebyshev nodes. In addition, we shall examine the influence of boundary conditions on the accuracy and stability of pseudospectral methods. In general, global methods are more sensitive to the boundary treatment than local methods. We also consider the effect of the location of the collocation points on both the accuracy and the stability of the scheme and its effect on the allowable time step for an explicit time integration algorithm.
GLOBALPROPERTIESOFPSEUDOSPECTRALMETHODS
2. APPROXIMATION
241
AND DIFFERENTIATION
We assume that we are given N + 1 distinct points x,, < x1 c . . . < x,,,. Given a functionf(x) it is well known how to interpolatef(x) by a polynomial PN(x) such that PN(xj) = f(xj), j = 0, .... N. We define a function ek(x) which is a polynomial of degree N and satisfies ek(xj) = Sjk. Explicitly,
ek(xl=$o (x-x,)
(2.la)
Ifk
ak=
Then the approximating formula,
;I I=0 l#k
polynomial
PN(X)
=
(2.lb)
@k-x,).
is given by the Lagrange
5 k=O
ftxk)
ek(X).
interpolation
(2.2)
We now construct an approximation to the derivative by analytically differentiating (2.2). The value of the approximate derivative at the collocation points is a linear functional of the value of the function itself at the collocation points. Hence, given the N + 1 values f(xj) we can find the values PA(x) by a matrix multiplying the original vector (f(x,), .... f(xN)). We denote this matrix by D = (djk). By construction, DP, = Pk is exact for all polynomials of degree N or less. In fact, an alternative way of characterizing D is by demanding that it give the analytic derivative for all such polynomials P. In particular, we shall explicitly construct D by demanding that, Dek(Xj) = e;(Xj), i.e.,
D
j, k = 0, .... N;
(2.3)
242
SOLOMONOFF
AND
TURKEL
Performing the matrix multiply, it is obvious that
djk= 2 (Xj).
(2.4)
We next explicitly evaluate djk in terms of the collocation points xj. Taking the logarithm of (2.1) we have log(e,) = f
log(x - x,) - log(+).
I=0 Ifk
Differentiating,
we have e;(x) = ek(x) 5 l/(x-x,).
(2.5)
I=0 I#k
In order to evaluate (2.5) at x = xi, j # k, we need to eliminate the zero divided by zero expression. We therefore rewrite (2.5) as fj l/(x-x,). I=0
e;(x)=ek(x)/(x-xj)+e,(x)
I# j,k
Since,
ek(xj)
= 0 for j # k we have that e;(xj) = liy
ek(x)/(x -
x,).
I
Using the definition of e,(x), (2.1), we have
(xj-X/)=a cx~~xk) djk=$ ,fio k I
I#j,k
see (2.lb)).
(2.7)
While the formulas (2.5), (2.7) are computationally useable, it is sometimes preferable to express the formulas slightly differently. We therefore rederive these formulas using a slightly different notation. Define
#N+I(X)= n (x-x,). N
(2.8)
I=0
Then,
&v+,(x)=g l?i (x-x,) k-0
I=0 Ifk
(2.9)
GLOBAL
PROPERTIES
OF PSEUDOSPECTRAL
METHODS
243
and so &‘+
ltxk)
(2.10)
=ak.
It can be verified that (2.11)
d~+l(xk)=2uj,$o&. I I#i
Hence,
j#k
(2.12a)
djk j=k.
(2.12b) N* operations are requested to compute aj. Given aj another 2N2 operations are required to find the off-diagonal elements by (2.12a). N* operations are required to find all the diagonal elements from (2.12b). Hence, it requires about 4N2 operations to construct the matrix D. If we multiply the matrix D on the left by diag( l/a,, .... l/a,) and on the right by the matrix diag(a,, .... a,,,), then D is similar to a matrix D, which is the sum of an antisymmetric matrix and a diagonal matrix. Since &,+ i is a polynomial of degree N - 1, di+, cannot be zero at all the collocation points. Hence, the diagonal portion of D, is nonzero. In many cases x0 = - 1, xN = 1 and the other xj are zeros of some polynomial QN- ,(x), Hence, #N+ i(x) = (x2 - 1) QN- i(x). One can then rewrite the formula for djk in terms of Q,+,(x). For j, k # 0, N we reproduce the formulas of Tal-Ezer [22]. He further points out that if QN- i(x) is a Jacobi polynomial associated with the weight function (1 -x)’ (1 + x)~ then (2.13) I#k
where the sum is over the roots of QN-,(x). This can then be used to simplify (2.12b). When the end points x = - 1 or x = 1 are included in the collocation points, these must be explicitly accounted for to find djk. For the standard Chebyshev collocation points, we have xi = cos(nj/N),
j = 0, .... N.
(2.14)
Note. The points are in reverse order from the usual ordering. One can also evaluate the derivative by using FFTs which requires only N log N operations.
SOLOMONOFFAND
244
TURKEL
Computationally it is found that for N? 100 the matrix multiplication is faster than the FFT approach; see, e.g., [23]. The exact crossover point depends on the computer and the efficiency of the software for computing FFTs and matrix multiplications. Multiplying by a matrix has the advantage that it is more flexible and vectorizable. For example, both the location and the number of the collocation points is arbitrary. In order to use the FFT approach, it is required that the collocation points be related to the Fourier collocation points, e.g., Chebyshev. Furthermore, the total number of collocation points needs to be factorizable into powers of 2 and 3 for efficiency. The efficiency of these factors depends on the memory allocation scheme of the computer. Other collocation nodes than (2.14) are considered in [3, 7, 131. The matrix D for the Chebyshev points (2.14) is given in [7]. An alternative to using matrix multiplication is to find the derivative by using finite differences and Newton’s interpolation formula based on xj, j = 0, .... N. Similarly for the second derivative we have j, k = 0, .... N,
D’2’e,(xj) = ei(x,), and so
= 2d, I# j,k
I#j,k
=2djk [dH-&], (,F,&,-,, I#k
j#k
(&‘x,)’ I#k
N
\
c -!I=0 xj-xI
=d
:k
-,;o
1 (xk-xl)”
j=k.
I#k
In Appendix A, we consider the problem when we have N collocation nodes and wish the derivative matrix to be exact (in least squares sense) for M> N functions which need not be polynomials.
3. PARTIAL DIFFERENTIAL
EQUATIONS
In this study we consider three applications of collocation methods: (1) approximation theory, (2) hyperbolic equations, and (3) elliptic equations. For approximation theory we need only discuss accuracy. We first need some way to measure the approximation error that can be used on a computer. We cannot use
GLOBAL
PROPERTIES
OF PSEUDOSPECTRAL
METHODS
the error at the collocation points since, by construction, we use
245
this error is zero. Instead,
(3.1) where w/E-- 17t CI N
and
Cl=
1, 2,
I#% N I=O, N
for some sequence of points x1 which are not the collocation points. In general, we shall choose N’ much larger than N, the number of collocation points. If the original points are chosen as Chebyshev nodes, then we again choose the x1, as Chebyshev nodes based on this larger number, N’. Because of this selection of nodes the sum in (3.1) approximates the Chebyshev integral norm; i.e., (3.2) When the collocation points are uniformly spaced, we can choose the nodes of the integration formula to be also uniformly spaced. In this case
llf-P,112=~~,
C”fw-W~)12~~.
(3.3)
For general collocation points it is not clear how to choose the weights w, in the norm. An alternative possibility is to measure the error in some Sobolev norm. In this case, the finite sum can be based on the original collocation points, and the norm is the L2 norm of the derivative. In this study all errors will be given by (3.2) regardless of the distribution of the collocation nodes. For hyperbolic problems we need to be concerned with stability in addition to accuracy. For simplicity we shall only consider the model equation u, =4x)
UC?,
-l x0 + l/M, and f(M) is a quintic polynomial in between. Furthermore, f(x) has two continuous derivatives, but the third derivative is discontinuous at x = x,, f l/M. Thus, as before, x0 denotes the center of the “jump” and the gradient
256
SOLOMONOFF
AND
TURKEL
becomes larger as M increases. In Fig. 7a, we plot the L2 error for Chebyshev collocation with 31 nodes. As x0 goes toward the boundary, there is a small decrease in the error, but not as pronounced as in Fig. 5a. We also note that the decrease in error is greater for M = 32 than for M = 2. Thus, in contrast to Fig. 5a, there is no longer a sharp decrease for smoother functions as x0 approaches 1. When using uniformly spaced points the absolute error is larger than when using Chebyshev points. However, now there is a large decrease in the error as x0 approaches the boundary. We compare the case M= 32; for Chebyshev collocation the error decrease by about two orders of magnitude as x0 varies from the center to the boundary. For uniformly spaced points the error decreases by about six orders of magnitude despite the fact that the Chebyshev collocation method bunches the points near the boundary. We also note that nothing special happens when x0 is sufficiently close to the boundary that the discontinuous third derivative at x0 + l/M is no longer in the domain. In Fig. 8a, we study the L2 error as we vary the strength of the singularity. Consider the function U(X) = H(x-x,)*(x -x~)~, where H(x) is the Heaviside function. Thus U(X) has a discontinuous Mth derivative. As expected, based on previous cases, we see that when the high order derivatives are discontinuous, the Chebyshev collocation method resolves the functions best when the discontinuity is near the boundary. However, when low order derivatives are discontinuous, the difference between the boundary and the center decreases. For a step function, M = 0, the error oscillates with equal amplitude throughout the domain. As x approaches the boundary only the frequency of the oscillation changes. In Fig. 8b, we see that the same qualitative picture occurs when the collocation is based on uniformly spaced points. We also see that global collocation based on uniformly spaced points is not convergent when the function is not smooth. This divergence is amplified if the discontinuity occurs near the center of the domain. In this case, the divergence is no longer caused by roundoff error. Rather it already occurs at moderate values of N and begins at larger error levels. For f(x) = 1x1 it can be proved [ 161 that collocation based on uniformly spaced nodes converges only for the points x=0, + 1, - 1. In order to further study the resolving power of the global schemes near the boundary, we consider the function
We plot the pointwise error in Fig. 9a for both Chebyshev nodes and for uniformly spaced nodes, For uniformly spaced nodes, the error is very small in the interior (see Fig. 9b for a logarithmically scaled plot), but is very large near, i.e., within O( l/N), x = 1. From Fig. 9b we see that the error is larger near x = - 1 than in the center. For the Chebyshev nodes, the error is more global, but the large error near the boundary is confined to an interval of size O(1/N2). The function e,,(x) (2.1) is one at the boundary and zero at all other nodes. Hence, Fig. 9a also is the graph
a
IO*-
-70.0
lO*m
2
IO**
-50.0
t
t
0.’
0.’
I
I
I 0.2
I
0.2
I 0.3
I
0.3
I 0.Y
0.4I
I
I 0.6
0.5I XZERO
0.6
XZiRO 0 5
I
I 0.7 -
I
0.7
.
I
0.8
.
I
0.9
1.0
I!0
FIG. 7.(a) L2 error of the approximation obtained by Chebyshev collocation using 31 nodes for the function given in (4.1). (b) Same as Fig. 7a but using uniformly spaced nodes and M= 2, 4, 8, 16, 32.
257
IO.. b IO..
10..
XZERO
VI
FIG. 8.(a) L’ error of the approximation obtained by Chebyshev collocation for f(x) = sgn(x (.x-qJ”, M=O, .. .. 5, using 30 nodes. We let x0 vary between 0 and 1. (b) Same as Fig. 8a but uniformly spaced collocation nodes but Chebyshev norm.
258
- x,,) using
10””
I
IO..
0
b
I;
FIG. 9.(a) We consider the function f(x) = 1 except at x = 1 when j(x) = 0. We graph the error for (solid line) Chebyshev nodes and (dotted line) uniformly spaced nodes, both using 31 collocation points. This is also the graph of the first basis function e,(x). (b) The case of uniformly spaced nodes of Fig. 9a plotted on a logarithmic scale. (c) Basis function e N,2(~) for the Chebyshev nodes with N = 33. (d) Basis function e&x) for the Chebyshev nodes with N = 33. (e) Basis function e N,Z(~) for evenly spaced nodes with N = 33.
3 P
D
GLOBAL
PROPERTIES
OF PSEUDOSPECTRAL
261
METHODS
I/”
v FIG.
9-Continued.
of eO(x) for the Chebyshev nodes and eN(x) for equally spaced nodes. In Fig. 9c and 9d, we plot e,,,,*(x) and e,,,,Jx) for the Chebyshev nodes. We note that the oscillations are what give rise to the high accuracy. For evenly spaced nodes the amplitude of ej(x) grows much faster and the peak is no longer at the point x0 but near the boundaries, as seen in Fig. 9e, where e&x) is plotted for evenly spaced nodes. We next consider the partial differential equation -l