Two algorithms for solving a general backward tridiagonal linear systems

Two algorithms for solving a general backward tridiagonal linear systems

Available online at www.sciencedirect.com Applied Mathematics and Computation 194 (2007) 534–539 www.elsevier.com/locate/amc Two algorithms for solv...

113KB Sizes 4 Downloads 89 Views

Available online at www.sciencedirect.com

Applied Mathematics and Computation 194 (2007) 534–539 www.elsevier.com/locate/amc

Two algorithms for solving a general backward tridiagonal linear systems A.A. Karawia Department of Mathematics, Faculty of Science, Mansoura University, Mansoura 35516, Egypt

Abstract In this paper we present an efficient computational and symbolic algorithms for solving a backward tridiagonal linear systems. The implementation of the algorithm using Computer algebra systems (CAS) such as Maple, Macsyma, Mathematica, and Matlab is straightforward. An examples are given in order to illustrate the algorithms.  2007 Elsevier Inc. All rights reserved. Keywords: Backward tridiagonal matrices; Tridiagonal matrices; Linear systems; Determinants; Computer algebra systems (CAS)

1. Introduction Many problems in mathematics and applied science require the solution of linear systems having a backward tridiagonal coefficient matrices. This kind of linear system arise in many fields of numerical computation [1,2]. The main goal of the current paper is to develop an efficient algorithms for solving a general backward tridiagonal linear systems of the form: AX ¼ Y ;

ð1:1Þ

where 2 6 6 6 6 6 A¼6 6 6 6 6 4a

0 0 0 .. . .. . n1

dn

0 0 0 .. . .. . d n1 bn

0 0 0

  

0 a2 d3





 

 bn1 0

  

  0 0 0 0

a1 d2 b3

3 d1 b2 7 7 07 7 .. 7 . 7 7; .. 7 . 7 7 05 0

X ¼ ðx1 ; x2 ; . . . ; xn ÞT , Y ¼ ðy 1 ; y 2 ; . . . ; y n ÞT and n P 3. E-mail address: [email protected] 0096-3003/$ - see front matter  2007 Elsevier Inc. All rights reserved. doi:10.1016/j.amc.2007.04.057

ð1:2Þ

A.A. Karawia / Applied Mathematics and Computation 194 (2007) 534–539

535

A general n · n backward tridiagonal matrix A of the form (1.2) can be stored in 3n  2 memory locations by using three vectors a ¼ ða1 ; a2 ; . . . ; an1 Þ, b ¼ ðb2 ; b3 ; . . . ; bn Þ, and d ¼ ðd 1 ; d 2 ; . . . ; d n Þ. When considering the system (1.1) it is advantageous to introduce one additional vector b ¼ ðb1 ; b2 ; . . . ; bn Þ. This vector is related to the vectors a, b, and d. The current paper is organized as follows. In Section 2, the main results are given. An illustrative examples are presented in Section 3. In Section 4, a Conclusion is given. 2. Main results In this section we are going to formulate a modified computational algorithm and an efficient symbolic algorithm for solving a general backward tridiagonal linear systems of the form (1.1). To do this we begin by translate the system (1.1) to the following tridiagonal linear system: A1 X ¼ Y 1 ;

ð2:1Þ

where 2

6 6 an1 6 6 0 6 6 6 . . A1 ¼ 6 6 . 6 . 6 . 6 . 6 6 4 0

3

bn

0



0

0

d n1

bn1



0

0

an2 .. . .. .

d n2 .. . .. .

bn2 .. . .. .

 .. . .. .

0  .. .

0

0



a2

d2

7 07 7 07 7 7 .. 7 . 7 7; .. 7 7 . 7 7 7 b2 5

0

0



0

a1

d1

dn

0

0

ð2:2Þ

T

Y 1 ¼ ðy n ; y n1 ; . . . ; y 1 Þ and n P 3. Now considering the LU decomposition [3] of the matrix A1 in the form: 3 2 bn 0  0 0 0 dn 7 6 0 0 07 6 an1 d n1 bn1    7 6 6 0 07 an2 d n2 bn2    0 7 6 7 6 7 6 . . . . . . . .    .. 7 .. .. .. 6 .. 7 6 6 . .. 7 .. .. .. .. .. 7 6 . 6 . . . 7 . . . . 7 6 7 6 0 0    a2 d 2 b 2 5 4 0 0

2

0 1

6 an1 6 b 6 1 6 6 0 6 6 6 . . ¼6 6 . 6 . 6 . 6 . 6 6 6 0 4 0



0

0

a1

0

0



0

0

1

0



0

0

an2 b2

1

0



0

..

..

.

..

.

..

.

..

.

.. . .. . 0 0

.. . 0 0

.

 

 .. .

a2 bn2

1

0

a1 bn1

d1

3 0 2b 7 1 6 07 76 0 76 6 07 76 0 76 6 . .. 7 6 . .7 76 . 7 .. 76 6 . . 76 .. 76 76 0 74 0 5 0 1

bn

0



0

0

b2

bn1



0

0

0

b3

bn2



0

.. . .. .

..

..

.

..

.

.. .

..

.

..

.

0

0



0

bn1

0

0



0

0

.

 .. .

0

3

07 7 7 07 7 7 .. 7 . 7 7: .. 7 7 . 7 7 7 b2 5 bn

ð2:3Þ

536

A.A. Karawia / Applied Mathematics and Computation 194 (2007) 534–539

From (2.3) we obtain ( dn bi ¼ d niþ1  abniþ1 bniþ2 i1

if i ¼ 1; if i ¼ 2ð1Þn;

ð2:4Þ

It is not difficult to prove that the LU decomposition (2.3) exists only if bi 6¼ 0; i ¼ 1ð1Þn  1. Moreover a general backward tridiagonal linear system (1.1) possesses a unique solution if, in addition, bn 6¼ 0. On the other hand, the Determinant of the matrix A1 is given by detðA1 Þ ¼

n Y

bi ;

ð2:5Þ

i¼1

and this shown the importance of the vector b [4]. We may now formulate the following results. Algorithm 2.1. To solve the general backward tridiagonal linear system (1.1), we may proceed as follows: Step 1: Set b1 = dn. Step 2: If b1 = 0, then OUTPUT(’the method is fails’); STOP. Step 3: For i ¼ 2; 3; . . . ; n Compute bi ¼ d niþ1  abniþ1 bniþ2 . i1 If bi = 0, then OUTPUT(’the method is fails’); STOP. Step 4: Set z1 = yn. Step 5: For i ¼ 2; 3; . . . ; n Compute zi ¼ y niþ1  abniþ1 zi1 . i1 Step 6: Compute the solution vector x using xn ¼ bznn , For i ¼ n  1; n  2; . . . ; 1 Compute xiþ1 xi ¼ zi bniþ1 . bi The new Algorithm 2.1 will be referred to as KBTRI algorithm. KBTRI algorithm for solving the backward tridiagonal system (1.1) is generally preferable because the conditions bi 6¼ 0; i ¼ 1ð1Þn are sufficient for the validity of it. The advantage of the vector b is now clear. The following symbolic algorithm is developed in order to remove the cases where the numeric algorithm KBTRI fails. Algorithm 2.2. To solve the general backward tridiagonal linear system (1.1), we may proceed as follows: Step 1: Set b1 = dn. Step 2: Set b1 = x(x is just a symbolic name) whenever b1 = 0. Step 3: For i ¼ 2; 3; . . . ; n Compute bi ¼ d niþ1  abniþ1 bniþ2 . i1 Set bi = x whenever bi = 0. Step 4: Set z1 = yn. Step 5: For i ¼ 2; 3; . . . ; n Compute zi ¼ y niþ1  abniþ1 zi1 . i1 Step 6: Compute the solution vector x using xn ¼ bznn , For i ¼ n  1; n  2; . . . ; 1 Compute xiþ1 xi ¼ zi bniþ1 . bi Step 7: Substitute x = 0 in all expressions of the solution vector xi ; i ¼ 1; 2; . . . ; n. The symbolic Algorithm 2.2 will be referred to as KSBTRI algorithm.

A.A. Karawia / Applied Mathematics and Computation 194 (2007) 534–539

537

Also in [5,6], the authors present an efficient algorithms to find the inverse of a general tridiagonal matrix A1. So we can use these methods to solve the linear system (2.1). In [7], the author given an efficient symbolic algorithm for solving a periodic tridiagonal sytems. 3. An illustrative examples In this section we are going to give an illustrative examples Example 3.1. Solve the backward tridiagonal linear system of size 10 given by 3 2 3 2 3 0 0 0 0 0 0 0 0 1 2 6 9 7 6 0 0 0 0 0 0 0 2 3 47 7 6 7 6 7 6 7 6 6 1 7 6 0 0 0 0 0 0 2 2 1 0 7 7 6 7 6 6 2 7 6 0 0 0 0 0 5 1 2 0 0 7 7 6 7 6 7 6 7 6 6 5 7 6 0 0 0 0 5 2 2 0 0 0 7 7 7X ¼ 6 6 6 3 7; 6 0 0 0 2 3 4 0 0 0 07 7 6 7 6 7 6 7 6 7 6 7 6 0 0 8 1 3 0 0 0 0 07 6 4 7 6 6 7 6 0 1 2 3 0 7 0 0 0 0 07 6 6 7 6 6 7 6 7 4 0 5 4 3 2 5 0 0 0 0 0 0 05 5 2

0

0

0

0

0

0

0 0

ð3:1Þ

3

by using the KBTRI algorithm and KSBTRI algorithm. Solution (i) The application of the KBTRI algorithm gives: • b1 = 5 (Step 1).   • ½b2 ; b3 ; b4 ; b5 ; b6 ; b7 ; b8 ; b9 ; b10  ¼ 165 57 ; 147 ;  185 ;  122 ; 246 ; 368 ; 429 ; 122 (Step 2). 16 19 49 37 61 123 184 429 • z1 = 3 (Step 3).   • ½z2 ; z3 ; z4 ; z5 ; z6 ; z7 ; z8 ; z9 ; z10  ¼  95 ; 105 ; 204 ; 11 ;  196 ; 368 ; 491 ; 1165 ; 122 (Step 4). 16 19 49 37 61 123 184 429 • x10 ¼ 1; ½x1 ; x2 ; x3 ; x4 ; x5 ; x6 ; x7 ; x8 ; x9  ¼ ½1; 1; 1; 1; 1; 1; 1; 1; 1; 1 (Step 5). Also we obtained the determinant of the current matrix detðA1 Þ ¼ 43920 by using (2.5). (ii) The application of the KSBTRI algorithm gives: X :¼ back_tri(b,d,a,y) = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]. Example 3.2. Solve the 2 0 0 0 1 6 6 0 0 3 2 6 6 0 2 1 4 6 6 4 5 2 7 0 0 3 0 0

backward tridiagonal linear system of size 5 given by 2 3 3 14 2 6 7 7 57 6 24 7 6 7 7 6 17 7; X ¼ 07 6 7 7 6 7 7 05 4 22 5 6 0

ð3:2Þ

by using the KBTRI algorithm and KSBTRI algorithm. Solution (i) The application of the KBTRI algorithm gives: The method is break down since b1 = d5 = 0. (ii) The application of the KSBTRI algorithm gives: h i ð98xþ1125Þ 4ð17xþ125Þ 25ð2xþ25Þ 125 ; ; ; X :¼ back triðb; d; a; yÞ ¼ 12xþ125 ; ð53x750Þ 3ð12xþ125Þ 3ð12xþ125Þ ð12xþ125Þ ð12xþ125Þ

x¼0

¼ ½1; 2; 3; 4; 5:

538

A.A. Karawia / Applied Mathematics and Computation 194 (2007) 534–539

4. Conclusion The methods described here are a very effective, provided optimal LU factorization is used. Our symbolic algorithm is competitive the other methods for solving a backward tridiagonal linear systems which appear in many applications. Acknowledgement I thank Prof. Dr. M.E.A. El-Mikkawy for several comments and suggestions. Appendix A. A Maple procedure for solving a backward tridiagonal linear systems Notes: The procedure is based on the following results: xi ¼

zi  bniþ1 xiþ1 ; bi

i ¼ n  1; n  2; . . . ; 1; xn ¼

zn : bn

where zi ¼ y niþ1 

aniþ1 zi1 ; bi1

i ¼ 2; 3; . . . ; n; z1 ¼ y n ;

and bi ¼ d niþ1 

aniþ1 bniþ2 ; bi1

i ¼ 2; 3; . . . ; n; b1 ¼ d n :

> # A Maple Procedure. > # Written by Dr. A. A. Karawia. > # Date: 30 May, 2006. > # To compute the solution of A general backward tridiagonal Linear systems. > restart: > with(linalg,vector,vectdim): > back_tri:¼proc(b::vector, d::vector, a::vector,y::vector) local i, j, n; global T, beta, z, X; n:¼vectdim(d):beta:¼array(1..n): z:¼array(1..n):X:¼array(1..n): #components of the vector beta # beta[1]:¼d[n]: if beta[1] = 0 then beta[1]:¼x;d[n]:¼x;fi: for i from 2 to n do beta[i]:¼simplify (d[n-i+1]-a[n-i+1]*b[n-i+2]/beta[i-1]); if beta[i] = 0 then beta[i]:¼x;fi: od: # To compute the vector Z # z[1]:¼y[n]: i:¼’i’: for i from 2 to n do z[i]:¼simplify (y[n-i+1]-a[n-i+1]*z[i-1]/beta[i-1]); od: # To compute the Solution of the system X. # X[n]:¼z[n]/beta[n]:i:¼’i’: for i from n-1 by 1 to 1 do X[i]:¼simplify((z[i]-b[n-i+1]*X[i+1])/beta[i]); od: # To compute the determinant T# T:¼subs(x = 0,simplify(product(beta[r],r=1..n)));

A.A. Karawia / Applied Mathematics and Computation 194 (2007) 534–539

539

eval(X): end: > # Call no. 1 for the procedure back_tri. # >x:¼’x’: >a:¼vector([1,2,2,5,5,2,8,1,3,0]); a:¼[1, 2, 2, 5, 5, 2, 8, 1, 3, 0] >d:¼vector([2,3,2,1,2,3,1,2,2,5]); d:¼[2, 3, 2, 1, 2, 3, 1, 2, 2, 5] >b:¼vector([0,4,1,2,2,4,3,3,5,2]); b:¼[0, 4, 1, 2, 2, 4, 3, 3, 5, 2] >y:¼vector([3,9,1,2,5,3,4,6,0,3]); y:¼[3, 9, 1, 2, 5, 3, 4, 6, 0, 3] >X:¼back_tri(b,d,a,y); X:¼[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] >T; 43920 > # End of call no. 1. # > # Call no. 2 for the procedure back_tri. # >x:¼’x’: >a:¼vector([1,2,2,5,5,2,8,1,3,0]); a:¼[1, 2, 2, 5, 5, 2, 8, 1, 3, 0] >d:¼vector([2,3,2,1,2,3,1,2,2,0]); d:¼[2, 3, 2, 1, 2, 3, 1, 2, 2, 5] >b:¼vector([0,4,1,2,2,4,3,3,5,3]); b:¼[0, 4, 1, 2, 2, 4, 3, 3, 5, 2] >y:¼vector([3,9,1,2,5,3,4,6,0,3]); y:¼[3, 9, 1, 2, 5, 3, 4, 6, 0, 3] >X:¼back_tri(b,d,a,y); h 102 X :¼ ð23xþ102Þ ; 3ð19xþ34Þ ; 6ð19xþ85Þ ; ð59xþ510Þ ; ð131xþ510Þ ; ð31xþ102Þ ; 1; ð23xþ102Þ 5ð23xþ102Þ 5ð23xþ102Þ 5ð23xþ102Þ ð23xþ102Þ i ð43xþ102Þ 17ðx6Þ ð43xþ102Þ ; ; ð23xþ102Þ ð23xþ102Þ ð23xþ102Þ >T; 24480 >x:¼0:X:¼map(eval,op(X)); X:¼[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] > # End of call no. 2. #

References [1] W. Cheney, D. Kincaid, Numerical Mathematics and Computing, second ed., Wadsworth, Inc., 1985. [2] H.L. Stone, Iterative solution of impilicit approximations of multidimensional partial differential equations, SIAM J. Numer. Anal. 5 (3) (1968) 530–558. [3] M.B. Allen III, E.L. Isaacson, Numerical Analysis for Applied Science, Wiley-Interscience, John Wiley & Sons, 1997. [4] M.E.A. El-Mikkawy, A fast algorithm for evaluating nth order tridiagonal determinants, J. Comput. Appl. Math. 166 (2004) 581–584. [5] M.E.A. El-Mikkawy, On the inverse of a general tridiagonal matrix, Appl. Math. Comput. 150 (3) (2004) 669–679. [6] M.E.A. El-Mikkawy, A.A. Karawia, Inversion of general tridiagonal matrices, Appl. Math. Lett. 19 (8) (2006) 712–720. [7] M.E.A. El-Mikkawy, A new computational algorithm for solving periodic tri-diagonal linear systems, Appl. Math. Comput. 161 (2) (2005) 691–696.