CH-01 (523167), страница 2
Текст из файла (страница 2)
That is:{V} = {V}T {V} = v11 + v22 + … + v322(6)For a L-by-M matrix having elements eij where the row index i ranges from 1to L and the column index j ranges from 1 to M, the transpose of this matrix whenits elements are designated as trc will have a value equal to ecr where the row indexr ranges from 1 to M and the column index c ranges from 1 to M because thistranspose matrix is of order M by L. As a numerical example, here is a pair of a3 × 2 matrix [G] and its 2 × 3 transpose [H]:6[G] = 53× 24−3−2 and−16−3[H] = [G]T = 2 ×35−24−1If the elements of [G] and [H] are designated respectively as gij and hij, thenhij = gji.
For example, from above, we observe that h12 = g21 = 5, h23 = g32 = –1, andso on. There will be more examples of applications of Equations 5 and 6 in theensuing sections and chapters.Having introduced the transpose of a matrix, we can now conveniently revisitthe addition of {D} and {E} in Figure 1 in algebraic form as {F} = {D} + {E} =[4 –3]T + [–3 1]T = [4+(–3) –3+1]T = [1 –2]T. The resulting sum vector is indeedcorrect as it is graphically verified in Figure 1.
The saving of space by use oftransposes of vectors (row matrices) is not evident in this case because all vectorsare two-dimensional; imagine if the vectors are of much higher order.Another noteworthy application of matrix multiplication and transposition is toreduce a system of linear algebraic equations into a simple, (or, should we say asingle) matrix equation. For example, if we have three unknowns x, y, and z whichare to be solved from the following three linear algebraic equations:© 2001 by CRC Press LLCx + 2 y + 3z = 45x + 6y + 7z = 8−2 x − 37 = 9(7)Let us introduce two vectors, {V} and {R}, which contain the unknown x, y,and z, and the right-hand-side constants in the above three equations, respectively.That is:x TV=xyz={ } [] y z and4TR=489={ } [] 89 (8)Then, making use of the multiplication rule of matrices, Equation 5, the systemof linear algebraic equations, 7, now can be written simply as:[C]{V} = {R}(9)where the coefficient matrix [C] formed by listing the coefficients of x, y, and z infirst equation in the first row and second equation in the second row and so on.
That is,1[C] = 5−226−3370 There will be more applications of matrix multiplication and transposition inthe ensuing chapters when we discuss how matrix equations, such as [C]{V} = {R},can be solved by employing the Gaussian Elimination method, and how ordinarydifferential equations are approximated by finite differences will lead to the matrixequations. In the abbreviated matrix form, derivation and explanation of computational methods becomes much simpler.Also, it can be observed from the expressions in Equation 8 how the transpositioncan be conveniently used to define the two vectors not using the column matriceswhich take more lines.FORTRAN VERSIONSince Equations 1 and 2 require repetitive computation of the elements in thesum matrix [S] and difference matrix [D], machine could certainly help to carry outthis laborous task particularly when matrices of very high order are involved.
Forcovering all rows and columns of [S] and [D], looping or application of DO statementof the FORTRAN programming immediately come to mind. The following programis provided to serve as a first example for generating [S] and [D] of two givenmatrices [A] and[B]:© 2001 by CRC Press LLCThe resulting display on the screen is:To review FORTRAN briefly, we notice that matrices should be declared asvariables with two subscripts in a DIMENSION statement. The displayed results ofmatrices A and B show that the values listed between // in a DATA statment will befilling into the first column and then second column and so on of a matrix. To instructthe computer to take the values provided but to fill them into a matrix row-by-row,a more explicit DATA needs to be given as:DATA ((A(I,J),J = 1,3),I = 1,3)/1.,4.,7.,2.,5.,8.,3.,6.,9./When a number needs to be repeated, the * symbol can be conveniently appliedin the DATA statement exemplified by those for the matrix [B].Some sample WRITE and FORMAT statements are also given in the program.The first * inside the parentheses of the WRITE statement when replaced by anumber allows a device unit to be specified for saving the message or the values ofthe variables listed in the statement.
* without being replaced means the monitorwill be the output unit and consequently the message or the value of the variable(s)will be displayed on screen. The second * inside the parentheses of the WRITE© 2001 by CRC Press LLCstatement if not replaced by a statement number, in which formats for printing thelisted variables are specified, means “unformatted” and takes whatever the computerprovides. For example, statement number 15 is a FORMAT statement used by theWRITE statement preceding it. There are 18 variables listed in that WRITE statementbut only six F5.1 codes are specified.
F5.1 requests five column spaces and one digitafter the decimal point to be used to print the value of a listed variable. / in aFORMAT statement causes the print/display to begin at the first column of the nextline. 6F5.1 is, however, enclosed by the inner pair of parentheses that allows it tobe reused and every time it is reused the next six values will be printed or displayedon next line.
The use (*,*) in a WRITE statement has the convenience of viewingthe results and then making a hardcopy on a connected printer by pressing the PrtSc(Print Screen) key.INTERACTIVE OPERATIONProgram MatxAlgb.1 only allows the two particular matrices having their elements specified in the DATA statement to be added and subtracted.
For finding thesum matrix [S] and difference matrix [D] for any two matrices of same order N, weought to upgrade this program to allow the user to enter from keyboard the orderN and then the elements of the two matrices involved. This is interactive operationof the program and proper messages should be given to instruct the user what to dowhich means the program should be user-friendly.
The program MatxAlgb.2 listedbelow is an attempt to achieve that goal:© 2001 by CRC Press LLCThe interactive execution of the problem solved by the previous version Matxalgb.1now can proceed as follows:© 2001 by CRC Press LLCThe results are identical to those obtained previously. The READ statementallows the values for the variable(s) to be entered via keyboard. A WRITE statementhas no variable listed serves for need of skipping a line to provide better readabilityof the display. Also the I and E format codes are introduced in the statement 10. Iwwhere w is an integer in a FORMAT statement requests w columns to be providedfor displaying the value of the integer variable listed in the WRITE statement, inwhich the FORMAT statement is utilized.
Ew.d where w and d should both be integerconstants requests w columns to be provided for display a real value in the scientificform and carrying d digits after the decimal point. Ew.d format gives more feasibilitythan Fw.d format because the latter may cause an error message of insufficient widthif the value to be displayed becomes too large and/or has a negative sign.MORE PROGRAMMING REVIEWBesides the operation of matrix addition and subtraction, we have also discussedabout the transposition and multiplication of matrices.
For further review of computerprogramming, it is opportune to incorporate all these matrix algebraic operationsinto a single interactive program. In the listing below, three subroutines for matrixaddition and subtraction, transposition, and multiplication named as MatrixSD,Transpos, and MatxMtpy, respectively, are created to support a program calledMatxAlgb (Matrix Algebra).© 2001 by CRC Press LLC© 2001 by CRC Press LLCThe above program shows that Subroutines are independent units all started witha SUBROUTINE statement which includes a name followed by a pair of parenthesesenclosing a number of arguments.
The Subroutines are called in the main programby specifying which variables or constants should serve as arguments to connect tothe subroutines. Some arguments provide input to the subroutine while other arguments transmit out the results determined by the subroutine. These are referred toas input arguments and output arguments, respectively. In many instances, an argument may serve a dual role for both input and output purposes. To construct as anindependent unit, a subprogram which can be in the form of a SUBROUTINE, orFUNCTION (to be elaborated later) must have RETURN and END statements.It should also be remarked that program MatxAlgb is arranged to handle anymatrix having an order of no higher than 25 by 25.
For this restriction and for havingthe flexibility of handling any matrices of lesser order, the Lmax, Mmax, and Nmaxarguments are added in all three subroutines in order not to cause any mismatch ofmatrix sizes between the main program and the called subroutine when dealing withany L, M, and N values which are interactively entered via keyboard.Computed GOTO and arithmetic IF statements are also introduced in the program MatxAlgb. GOTO (i,j,k,…) C will result in going to (execute) the statementnumbered i, j, k, and so on when C has a value equal to 1, 2, 3, and so on, respectively.IF (Expression) a,b,c will result in going to the statement numbered a, b, or c if thevalue calculated by the expression or a single variable is less than, equal to, or,greater than zero, respectively.It is important to point out that in describing any derived procedure of numericalcomputation, indicial notation such as Equation 5 should always be preferred tofacilitate programming.
In that notation, the indices are directly used, or, literallytranslated into the index variables for the DO loops as can be seen in SubroutineMatxMtpy which is developed according to Equation 5. Subroutine MatrixSD isanother example of literally translating Equations 1 and 2. For defining the valuesof the element in the following tri-diagonal band matrix:© 2001 by CRC Press LLC1−3[C ] = 00 021−300021−300021−300021 we ought not to write 25 separate statements for the 25 elements in this matrix butderive the indicial formulas for i,j = 1 to 5:cij = 0,if j > i + 2, or, j < i − 2ci,i +1 = 2,andci,i −1 = −3Then, the matrix [C] can be generated with the DO loops as follows:The above short program also demonstrates the use of the CONTINUE statement for ending the DO loop(s), and the logical IF statements.