Appendix C Some Details of Matrix.Xla(M)
Total Page:16
File Type:pdf, Size:1020Kb
Appendix C Some details of Matrix.xla(m) C.1 Matrix nomenclature For the sake of notational compactness, we will denote a square diagonal matrix by D with elements dii, a square tridiagonal matrix by T with elements tij where | j – i | ≤ 1, most other square matrices by S, rectangular matrices by R, and all matrix elements by mij. A vector will be shown as v, with elements vi, and a scalar as s. Particular values are denoted by x when real, and by z when complex. All optional pa- rameters are shown in straight brackets, [ ]. All matrices, vectors, and scalars are assumed to be real, ex- cept when specified otherwise. All matrices are restricted to two dimensions, and vectors to one dimen- sion. Table C.1 briefly explains some matrix terms that will be used in subsequent tables. With some functions, the user is given the integer option Int of applying integer arithmetic. When a matrix only contains integer elements, selecting integer arithmetic may avoid most round-off problems. On the other hand, the range of integer arithmetic is limited, so that overflow errors may result if the ma- trix is large and/or contains large numbers. Another common option it Tiny, which defines the absolute value of quantities that can be regarded as most likely resulting from round-off errors, and are therefore set to zero. When not activated, the routine will use its user-definable default value. Condition of a matrix: ratio of its largest to smallest singular value Diagonal of a square matrix: the set of terms mij where i = j Diagonal matrix D square matrix with mij = 0 for all off-diagonal elements i ≠ j. Decomposition or factorization: writing a matrix as the product of two or more special matrices False as optional parameter: False = 0 First lower subdiagonal of a square matrix: the set of terms mij where j = i+1 First upper subdiagonal of a square matrix: the set of terms mij where j = i–1 Inverse square matrix S–1 square matrix that satisfies S–1 S = S S–1 = I Hermitean matrix a square matrix for which S*T = S where S* denotes the complex conjugate of S; all symmetric real matrices are Hermitian Hessenberg matrix H a square matrix with mij = 0 for j = i+k, k > 1 Lower triangular matrix L a square matrix with only 0’s below its diagonal Order of a square matrix: its number of rows or columns Orthogonal matrix a real, square matrix with the property S–1 = ST Rank order of largest nonsingular square submatrix of a matrix Rectangular matrix R a matrix with (in general) an unequal number of rows and columns Square matrix S a matrix with an equal number of rows and columns Subdiagonal the set of terms mij where i = j±k where k is an integer T Symmetric matrix a square matrix S with all mij = mji, hence S = S Toeplitz matrix a square matrix with constant elements on each diagonal parallel to the main diagonal Transpose RT matrix after interchanging its rows and columns Triangular matrix T matrix with non-zero terms only on its diagonal and first upper and lower subdiagonals True as optional parameter: True = 1 Uniform matrix repeats its elements on its diagonal and each subdiagonal Unit matrix I square matrix of arbitrary dimension m×m with 1’s on its diagonal, and 0’s above and below it Upper triangular matrix U a square matrix with only 0’s below its diagonal. (Exceptions: the upper triangular matrix R in QR decomposition; the orthogonal matrix U in singular value decomposition.) Table C-1: The nomenclature used 599 C.2 Functions for basic matrix operations C.2.1 Functions with a scalar output Entering the functions listed below does not require the use of Ctrl∪Shift∪Enter. 2 MAbs(R) Absolute value of R ∑mij i, j MCond(R) Condition number κ of a matrix κ computed using singular value decomposition MpCond(R) –log10 of matrix condition number pκ = –log(κ) computed using singular value decomposition MDet(S [,Int] [,Tiny]) Determinant of a square matrix S det[S] Similar to Excel’s =MDETERM(S). Because of rounding errors, both MDET and MDETERM can yield (often different) non-zero answers For a singular matrix. When all elements of S are integer, and Integer is set to True, MDET uses integer mode. Defaults: Integer = False, Tiny = 0. MRank(R) Rank of a matrix MTrace(S) Trace of a square matrix tr(S) = ∑mii i C.2.2 Basic matrix functions Entering the following functions requires the use of Ctrl∪Shift∪Enter MAdd(R1,R2) Addition of two matrices R1+R2 equivalent to Excel’s =R1+R2, as in =B2:D5+F2:H5. MSub(R1,R2) Subtraction of two matrices R1–R2 Equivalent to Excel’s = R1–R2, as in =B2:D5–F2:H5. MT(R) Transpose of a matrix RT equivalent to Excel’s function TRANSPOSE MMult(R1,R2) Product of two matrices R1 R2 Excel’s function is listed here for the sake of completeness MProd(R1,R2,R3,...) Product of two or more matrices R1R2R3... Pay attention to the dimensions, as the function MProd does not check them. MMultS(R,s) Product of a matrix and a scalar sR = Rs equivalent to Excel’s scalar multiplication, as in =3.21*B2:G9. MPow(S,n) Sn = S S S … S (n terms) Sn –1 MInv(S [,Int] [,Tiny]) Inverse of S S similar to Excel’s =MINVERSE(M). Because of rounding errors, both M_INV(M) and MINVERSE(M) can yield (different) non-zero element values for a singular matrix. When Integer is set to True, integer mode is used. Any result smaller in absolute magnitude than Tiny is set to zero. Defaults: Integer = False, Tiny = 0. ∞ n S S MExp(S [,Algo] [,n]) Matrix exponential e = ∑ n=0 n! Uses Padé approximation (the default, Algo = “P”), otherwise the power method. The default stops when convergence is reached. When n is specified, the resulting error can be obtained with =MExpErr(S, n) MExpErr (S ,n) Error term in matrix exponential 600 C.2.3 Vector functions ProdScal(v1,v2) Scalar product of two vectors v1 • v2 ProdVect(v1,v2) Vector product of two vectors v1 v2 v • v VectAngle(v ,v ) Angle between two vectors arccos 1 2 1 2 v1 ⋅ v2 C.3: More sophisticated matrix functions Diagonal or tridiagonal square matrices occur quite frequently in practical problems. When such matrices are of high orders, they can take up a large amount of space, even though most of it will be occupied by zeros. It is then often convenient to store and display m×m diagonal matrices D in compact notation as single m×1 column vectors, and tridiagonal matrices T as m×3 rectangular matrices. A number of special instructions are provided for this space-saving approach. Don’t confuse compact notation with sparse notation, as used in con- nection with sparse matrices, see Table C.10.3. MDetPar(S) Determinant of S containing one symbolic parameter k det[S] Used with Ctrl∪Shift∪Enter yields vector, otherwise output shown as text string. MDet3(T) Determinant of T in n×3 format det[T] There is no need to use Ctrl∪Shift∪Enter, because the output is a scalar. MMult3(T,R) Multiplies a tridiagonal matrix in tricolumnar format T R with a rectangular or square matrix R, or even a vector v. MMultTpz (S,v) Multiplies a Toeplitz matrix in compact (columnar) format and a vector v. For a Toeplitz matrix of order 2n+1, v must be n×1 –1 MBAB(S1,S2) Similarity transform S1 S2 S1 MBlock(S) Transforms reducible, sparse square matrix into block-partitioned form MBlockPerm(S) The permutation matrix for MBlock MDiag(v) Convert vector v into D mii = vi MDiagExtr(S [,d]) Extract the diagonal of S d = 1 for the diagonal, i = j (the default), d = 2 for the first lower subdiagonal, i = j+1. C.4: Functions for matrix factorization The terms matrix factorization and matrix decomposition refer to the same operations, in which a given matrix is expressed as the product of two or more special matrices. This approach is often used to facili- tate finding the required solution. The differences between the various available approaches reflect their general applicability, numerical efficiency, tolerance of ill-conditioning, etc. T SVDD(R) Yields D of R = U D V D The central result of singular value decomposition, providing the singular values σi as well as easy routes to matrix rank r and condition number κ. When R is Hermitian, the σi are the absolute values of its eigenfunctions. Note: the traditional symbol U here does not imply an upper triangular matrix. SVDU(R) Yields U of R = UT D V U SVDV(R) Yields V of R = UT D V V MCholesky(S) Cholesky decomposition S = L L–1 of a symmetric matrix M into a lower triangular square matrix L and its transpose LT 601 MLU(S [,pivot]) LU decomposition into a lower (L) and upper (U) triangular square matrix. S = L U The optional pivot (the default) activates partial pivoting MOrthoGS(R) Modified Gram-Schmidt orthogonalization T MQH(S,v) decomposition of S with vector b S = Q H Q Q is orthogonal, H is Hessenberg. If S is symmetric, H is tridiagonal MQR(R) QR decomposition A = Q R Q is orthogonal, R is upper triangular MHessenberg(S) Converts S into its Hessenberg form H MChar(S, x) Computes characteristic matrix at real value x If x complex, use MCharC(S, z) MCharPoly(S) Computes characteristic polynomial of S Can often be combined with PolyRoots(P) PolyRoots(P) Finds all roots of a polynomial P PolyRootsQR(P) Finds all roots of a polynomial P using the QR algorithm MNorm(R or v [,Norm]) Finds the matrix or vector norm For matrix R: Norm: 0 (default) = Frobenius, 1 = max.