Applied Mathematics and Computation 132 (2002) 341–351 www.elsevier.com/locate/amc
A modified spectral method for numerical solution of ordinary differential equations with non-analytic solution E. Babolian a, M.M. Hosseini
b,*
a
b
Institute of Mathematics, University for Teacher Education, Tehran 15614, Iran Department of Mathematics, Tarbiat Modarres University, P.O. Box 14115-114, Tehran, Iran
Abstract In this article, there is an attempt to introduce, generally, spectral methods for numerical solution of ordinary differential equations, also, to focus on those problems in which some coefficient functions or solution function is not analytic. Then, by expressing weak and strong aspects of spectral methods to solve this kind of problems, a modified spectral method which is more efficient than other spectral methods is suggested. Furthermore, with providing some examples, the aforementioned cases are dealt with numerically. Ó 2002 Elsevier Science Inc. All rights reserved. Keywords: Spectral methods; Boundary value problems; Orthogonal polynomials
1. Introduction Since the time of Fourier (1882), spectral representations in analytic study of differential equations are used and their applications for numerical solution of ordinary differential equations refers, at least, to the time of Lanczos [7]. Moreover, origin of some current spectral methods can be found in ‘‘weighted residual method’’ of Finlayson and Scriven [3]. However, in past two decades,
*
Corresponding author. E-mail addresses:
[email protected] (E. Babolian),
[email protected]. ac.ir (M.M. Hosseini). 0096-3003/02/$ - see front matter Ó 2002 Elsevier Science Inc. All rights reserved. PII: S 0 0 9 6 - 3 0 0 3 ( 0 1 ) 0 0 1 9 7 - 7
342
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
spectral methods with their current forms appeared as attractive ways in most applications and in some areas as preferred ways. Consider the following differential equation: Ly ¼
M X
ðfMi ðxÞDi Þy ¼ FR ðxÞ;
x 2 ½a; b;
ð1aÞ
i¼0
Ty ¼ C;
ð1bÞ
where fi ; i ¼ 0; 1; . . . ; M, FR are known real functions of x, Di denotes ith order differentiation with respect to x, T is a linear functional of rank N and C 2 RM . The basic of spectral methods to solve this class of equations is to expand the solution function, y, in (1a) and (1b) and as a finite series of very smooth basis functions, as given below yðxÞ
N X
ak /k ðxÞ
ð2Þ
i¼0
in which /k represents, for example, Chebyshev or Legendre polynomials. Now, if function y belongs to C 1 ½a; b, the produced error of approximation (2), when N tends to infinity, approaches zero with exponential rate [1]. This phenomenon is usually referred to as ‘‘spectral accuracy’’ [5]. The accuracy of derivatives obtained by direct, term-by-term differentiation of such truncated expansion, naturally deteriorates [1], but for low-order derivatives and sufficiently high-order truncations this deterioration is negligible, compared to the restrictions in accuracy introduced by typical difference approximations. So, often in numerical solution of (1a) and (1b), if solution function and coefficient functions are analytic on ½a; b, spectral methods will be very efficient and suitable. In this article, the focus of study is on problems that, at least, one of the coefficient functions or solution function is not analytic on ½a; b and then, weak aspects of spectral methods in solving this kind of problems are studied. Finally, a modified spectral method which comparing with the existing one is more efficient, is proposed.
2. Numerical solution of ODEs by spectral methods In this section, spectral methods for numerical solution of ordinary differential equations are briefly introduced. For this reason, first, consider the following differential equation: P ðxÞy 00 þ QðxÞy 0 þ RðxÞy ¼ SðxÞ; yð1Þ ¼ a;
yð1Þ ¼ b:
x 2 ½1; 1;
ð3aÞ ð3bÞ
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
343
It must be noted that the discussion in this section can simply extend to the general form (1a) and (1b). First, for an arbitrary natural number N, we suppose that the approximate solution of Eqs. (3a) and (3b), is yðxÞ
N X
ak Tk ðxÞ;
k¼0 t
N
where a ¼ ða0 ; a1 ; . . . ; aN Þ 2 RN þ1 and fTk gk¼0 is the sequence of Chebyshev polynomials of the first kind. Now, if we put V ðxÞ ¼
N X
ak Tk ðxÞ;
ð4Þ
k¼0
matrices A, Að1Þ , Að2Þ , and AA can be defined as follows [4]: 1; i ¼ j; V () A; Aij ¼ 0 otherwise; ð1=ci Þ 2j; i þ j odd; j > i; ð1Þ Vx () Að1Þ ; Aij ¼ 0 otherwise; ð1=ci Þ ðj iÞjðj þ iÞ; i þ j even; j > i; ð2Þ Vxx () Að2Þ ; Aij ¼ 0 otherwise; with 0 6 i; j 6 N and 2; i ¼ 0; ci ¼ 1; i > 0; AA ¼ P ðxÞAð2Þ þ QðxÞAð1Þ þ RðxÞA 2 RðxÞ QðxÞ 4P ðxÞ 3QðxÞ 6 RðxÞ 4QðxÞ 24P ðxÞ 6 6 RðxÞ 6QðxÞ 6 ¼6 RðxÞ 6 6 4
32P ðxÞ 8QðxÞ 48P ðxÞ 8QðxÞ RðxÞ .. .
3 7 7 7 7 ; 7 7 7 5
such that (3a) converts to N X
ai /i ðxÞ SðxÞ
i¼0
in which /i ðxÞ ¼
i X ðAAÞki Tk ðxÞ; k¼0
ð5Þ
344
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
that is, /0 ðxÞ ¼ RðxÞT0 ðxÞ; /1 ðxÞ ¼ QðxÞT0 ðxÞ þ RðxÞT1 ðxÞ; /2 ðxÞ ¼ 4P ðxÞT0 ðxÞ þ 4QðxÞT1 ðxÞ þ RðxÞT2 ðxÞ; .. . It must be noted that, if Aðkþ2Þ ; k P 1 be corresponding matrix of ðk þ 2Þth order differentiation of V ðxÞ, it follows that [4]: ðkþ2Þ
Aij
ðkÞ
¼ Aij
ðj i kÞðj þ i þ kÞðj i þ kÞðj þ i kÞ ; 4kðk þ 1Þ
0 6 i; j 6 N :
Now, if we impose boundary condition (3b) on V ðxÞ we have: N X
V ð1Þ ¼ a )
ak Tk ð1Þ ¼
k¼0
V ð1Þ ¼ b )
N X
ak Tk ð1Þ ¼
k¼0
N X
k
ak ð1Þ ¼ a;
k¼0 N X
ak ¼ b:
k¼0
So
1 1 1 1
1 1
... ...
2 3 a0
7
N 6 a ð1Þ 6 a1 7 : 6 .. 7 ¼ b 4 . 5 1 aN
ð6Þ
Relation (6) forms a system with two equations and N þ 1 unknowns, to construct the remaining N 1 equations we use one of the following methods. 2.1. Tau method In this method, we multiply both sides of (5) by Z 1 2 Tj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx; j ¼ 0; 1; . . . ; N 2; cj p 1 1 x2 to obtain
Z 1 Z 1 N 2 X /i ðxÞTj ðxÞ 2 SðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx; ai 2 cj p i¼0 cj p 1 1 x2 1x 1 j ¼ 0; 1; . . . ; N 2:
ð7Þ
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
345
Here, to compute the right-hand side of (7) it is sufficient to use an appropriate numerical integration method such as Guass–Chebyshev method. In addition, to compute the left-hand side of (7), first, we extend each function as: P ðxÞ
N X
ni Ti ðxÞ;
i¼0
QðxÞ
N X
ci Ti ðxÞ;
ð8Þ
i¼0
RðxÞ
N X
ki Ti ðxÞ:
i¼0
Using [2]: Z
1
1
8 < p; Ti ðxÞTk ðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ p2 di;k ; :p 1 x2 ðdj;iþk þ dj;jikj Þ; 4
with
di;j ¼
1; 0;
i ¼ k ¼ j ¼ 0; i þ k > 0; j ¼ 0; j > 0;
i ¼ j; i 6¼ j;
(6) and (7) make a system with N þ 1 equations and N þ 1 unknowns a0 ; a1 ; . . . ; aN . 2.2. Galerkian method This method is similar to tau method, where N 1 basis functions w2 ; w3 ; . . . ; wN , are obtained through Chebyshev polynomials T0 ; T1 ; . . . ; TN , in order to satisfy both boundary conditions (3b). Then we multiply both sides of (5) by Z 1 wj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx; j ¼ 2; 3; . . . ; N ; 1 x2 1 to obtain N 1 equations. 2.3. Pseudospectral method In this method, we substitute points xj ¼ cosðpj=N Þ; j ¼ 1; 2; . . . ; N 1, in (5) and put: N X
ai /i ðxj Þ ¼ Sðxj Þ;
i¼0
to obtain N 1 equations.
j ¼ 1; 2; . . . ; N 1;
ð9Þ
346
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
At the end of this section Example 1, chosen from [6], is solved using pseudospectral, e y ps and tau, e y s , methods. Table 1 shows the power of spectral methods in solving this kind of problems (solution function and coefficient functions are all analytic). The algorithms of all presented methods in this article, are performed using Maple V with 20 digits precision. Example 1. y 00 ¼
ð1 xÞ 2
ð1 þ xÞ
yð0Þ ¼ 1;
yþ
1 2
ð1 þ xÞ
;
x 2 ½0; 1;
1 yð1Þ ¼ ; 2
with the exact solution yðxÞ ¼ 1=ð1 þ xÞ.
3. Numerical solution of ODEs with non-analytic coefficient functions or solution function If f ðxÞ be a non-analytic function on ½1; 1 and f ðxÞ
N X
ai Ti ðxÞ;
ð10Þ
i¼0
then the order of infinite norm of the error of approximation (10) is given by Table 2, [4]. In the regular case, the decreased rate of expansion coefficients in (10) is similar to the order of infinite norm of the error at the points which are far away from irregular points. Here, the cases in which, at least, one of the coefficient functions or solution function is not analytic will be studied. Also, the produced difficulties in solving differential equation (3a) and (3b) by tau (as representative of tau and Galerkian methods) and pseudospectral methods will be considered. Case (I): Solution function, y, in (3a) and (3b) is analytic but, at least, one of the coefficient functions is not analytic. In this case, if we solve problem (3a) and
Table 1 N 8 15 20
kyðxÞ e y s ðxÞk1 6
1:15 10 4:17 1012 5:15 1016
kyðxÞ e y ps ðxÞk1 4:60 107 1:80 1012 2:60 1016
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
347
Table 2 Function
Order of infinite norm error Close to irregular points
Far from irregular points
f, discontinuous
1
f 0 , discontinuous
1 N 1 N2
1 N 1 N2 1 N3
00
f , discontinuous .. .
.. .
.. .
(3b) by tau method, the error produced from expansion of, at least, one of the coefficient functions in (8) follows from Table 2. So, in making system (7) (comparing with approximate error of solution function) the error is considerable and causes undesirable effect on final solution. Now, if this problem is solved by pseudospectral method, since solution function, y, is analytic and coefficient functions do not need expansion in form of (8), the produced error from making system (9), is much less than (7). Therefore, in this case, pseudospectral method is more successful than the tau method. Example 2 considers a problem of this kind. Example 2. 1 0 s s ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi 2 2 3 3 1 1 A; y 00 þ jxjy 0 þ y ¼ ex @1 þ jxj þ x2 x2 4 4 yð1Þ ¼ e1 ;
x 2 ½1; 1
yð1Þ ¼ e;
with the exact solution yðxÞ ¼ ex . In the above example, solution function is analytic on ½1; 1 but QðxÞ and RðxÞ are not analytic functions. Table 3 shows the results of solving this problem by pseudospectral, e y ps , and tau, e y s ; methods. Case (II): Solution function and, at least, one of the coefficient functions are not analytic. In this case, since the order of infinite norm of the error producing from approximation of solution function and, at least, one of the coefficient functions follows from Table 1, system (7) or (9) does not produce accurate results. The above case results from this fact that the representing matrices A,
Table 3 N 8 11 16
kyðxÞ e y s ðxÞk1 6
3:13 10 6:40 108 3:92 108
kyðxÞ e y ps ðxÞk1 3:24 108 2:52 1012 3:50 1018
348
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
Að1Þ , Að2Þ , and AA because of existing a non-analytic solution function, accompany the error which is indispensable. However, if other errors involves in the process of solving the problem, the error resulting from making (7) and (9) systems increases. And, finally, we will be far from the real solution. Here, a modified spectral method is suggested in such a way that considerably decreases the error in setting up the system of equations (to determine a ¼ t ða0 ; a1 ; . . . ; aN Þ ).
4. The modified spectral method This method is used for solving problem (3a) and (3b) when solution function and, at least, one of the coefficient functions are not analytic (nonanalyticity of solution function is recognized from the low rate of decrease in the coefficients of expansion of y). Again, consider relation (7):
Z 1 Z 1 N 2 X /i ðxÞTj ðxÞ 2 SðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx; ai 2 cj p i¼0 cj p 1 1 x2 1x 1 j ¼ 0; 1; . . . ; N 2;
ð11Þ
and assume that the ai ’s, 1 < a1 < a2 < < am < 1, are irregular points of coefficient functions. In this case, we put Z
1
1
/i ðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ 1 x2
Z
Z a2 /i ðxÞTj ðxÞ /i ðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx þ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx 2 1x 1 x2 1 a1 Z 1 /i ðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx; þ þ 1 x2 am a1
ð12Þ
Here, since integrated functions, in the right-hand side of (12), are analytic on ðai ; aiþ1 Þ, their values can be obtained by suitable numerical integration methods (such as Guass–Legendre). Also, if an intelligent programming is provided, division of intervals in (12) only includes those terms of integration Z
1
pffiffiffiffiffiffiffiffiffiffiffiffiffi /i ðxÞTj ðxÞ= 1 x2 dx;
1
whose integrands are not analytic. In any case, by using this kind of method, the error of setting up the system of equations will be less than similar methods, i.e., pseudospectral and tau algorithms. Example 3 considers a problem in which solution function belongs to C 2 ½1; 1 and one of the coefficient functions belongs to C½1; 1. This problem is solved by modified spectral, e y ms ,
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
349
Table 4 N
kyðxÞ e y s ðxÞk1
kyðxÞ e y ps ðxÞk1
kyðxÞ e y ms ðxÞk1
8 15 20
8:98 102 1:54 102 1:68 102
1:21 101 1:76 102 1:92 102
3:82 103 5:61 104 1:81 104
pseudospectral, e y ps , and tau, e y s , methods. As will be seen, the infinite norm of the error of pseudospectral method with N ¼ 20 is greater than the infinite norm of the error for modified spectral method with N ¼ 8. The results are represented in Table 4. Example 3. y 00 þ jxjy 0 þ y ¼ j6xj þ jx3 j þ 3x3 ; yð1Þ ¼ 1;
x 2 ½1; 1;
yð1Þ ¼ 1;
the exact solution, y, is yðxÞ ¼ jx3 j. Here, in using modified spectral method, the represented integrals in (11) are divided to ½1; 0 and ½0; 1 and for computing them Guass–Legendre numerical integration method, with Nz ¼ 16, is used, i.e., Z 1 Z 0 Z 1 /i ðxÞTj ðxÞ /i ðxÞTj ðxÞ /i ðxÞTj ðxÞ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx þ pffiffiffiffiffiffiffiffiffiffiffiffiffi dx; 2 2 1x 1x 1 x2 1 1 0
,sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
2ffi Z Z 0 /i ðxÞTj ðxÞ 1 1 t1 t1 t1 pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ 1 dt / Tj 2 1 i 2 2 2 1 x2 1
,sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
2 Nz 1X xk 1 xk 1 xk 1 1 / Tj wk ; 2 k¼0 i 2 2 2 Z 0
1
,sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
2ffi tþ1 tþ1 tþ1 1 dt /i Tj 2 2 2 1
,sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
2 Nz X 1 xk þ 1 xk þ 1 xk þ 1 1 /i Tj wk ; 2 k¼0 2 2 2
/i ðxÞTj ðxÞ 1 pffiffiffiffiffiffiffiffiffiffiffiffiffi dx ¼ 2 1 x2
Z
1
where xk ’s are roots of Legendre polynomials with Nz þ 1 degree and wk ’s are weigths according to Guass–Legendre numerical integration [1]. This section will be ended by representing another example.
350
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
Example 4. ( 2 1 2x 1 2 3 x þ 1 y 00 þ x 1 y 0 þ y ¼ x2 1 x þ 6x x 3 3 9 9 3 3 )
2 1 ; x 2 ½1; 1 þ 30x2 x þ 3 3
yð1Þ ¼
3 8 ; 9
yð1Þ ¼
3 8 ; 9 3
with the exact solution yðxÞ ¼ jðx2 19Þ j. The above problem is solved by expansion of solution function according to Legendre functions (to determine A, Að1Þ , Að2Þ , and AA matrices refer to [4]). And since irregular points of coefficient functions are 1=3 and 1=3, division of subintervals in (12) are ½1; 1=3, ½1=3; 1=3, and ½1=3; 1. Thus solution of this problem, again, indicates the efficiency of modified spectral method compared with other spectral methods. Fig. 1 shows the absolute error produced from pseudospectral, jyðxÞ e y ps ðxÞj, and modified spectral, jyðxÞ e y ms ðxÞj, methods (when N ¼ 24 and Nz ¼ 16).
Fig. 1. The absolute error functions produced from pseudospectral, - - - -, and modified spectral, ———, methods.
E. Babolian, M.M. Hosseini / Appl. Math. Comput. 132 (2002) 341–351
351
References [1] C. Canuto, M. Hussaini, A. Quarteroni, T. Zang, Spectral Methods in Fluid Dynamics, Springer, Berlin, 1988. [2] L.M. Delves, J.L. Mohamed, Computational Methods for Integral Equations, Cambridge University Press, Cambridge, 1985. [3] A. Finlayson, L.E. Scriven, The method of weighted residuals: a review, Appl. Mech. Rev. 19 (1966) 735–748. [4] B. Fornberg, A Practical Guide to Pseudospectral Methods, Cambridge University Press, Cambridge, 1996. [5] D. Gottlieb, S. Orszag, Numerical Analysis of Spectral Methods: Theory and Applications, SIAM, Philadelphia, PA, 1977. [6] C.P. Katti, S. Goel, A parallel mesh chopping algorithm for a class of two-point B.V.Ps, J. Comput. Math. Appl. 35 (8) (1998) 35–61. [7] C. Lanczos, Trigonometric interpolation of empirical and analytical functions, J. Math. Phys. 17 (1938) 123–129.