CPL
Page: (matrix)Top, Next: (graphics), Prev: (fft), Up: (cpl)Library Index

Matrix Operations

The rbmat.cpl and cbmat.cpl libraries add matrix algebra to CPL. The same functions and operators are defined in both, for real and complex numbers respectively, and therefore their result type is indicated as just number in what follows. Wherever a square matrix is expected, a banded matrix in compact rectangular form may also be used; the latter is recognized from its dimensions not being equal, and is defined as having the value zero of its second index as the diagonal. Most of the following functions have an equivalent infix form that allows matrix operations to be specified in the usual algebraic notation. The operands of matrix operations undergo automatic (cpl)realignment.`
Page: (matrix)MatEqu, Next: DotProduct, Prev: Top, Up: Top Index

SUBROUTINE MatEqu(POINTER TO ARRAY(∗,∗) OF number c; number a)

Assigns the scalar (REAL or COMPLEX) value <a> to the diagonal elements of matrix <c>, and zeros all the non-diagonal elements. Equivalent infix notation: c = a
Page: (matrix)DotProduct, Next: LeftMult, Prev: MatEqu, Up: Top Index

number FUNCTION DotProduct(ARRAY(∗) OF number a,b)

Computes the sum of products of the elements of <a> and <b>. Equivalent infix notation: a ∗ b

COMPLEX FUNCTION DotProduct2(ARRAY(∗) OF COMPLEX a,b)

Computes CONJG(a)∗b Equivalent infix notation: a | b
Page: (matrix)LeftMult, Next: RightMult, Prev: DotProduct, Up: Top Index

SUBROUTINE LeftMult(ARRAY(∗) OF number c^; ARRAY(∗,∗) OF number A; ARRAY(∗) OF number b)

Computes the left-hand product of matrix <A> by vector <b>, that is c(i)=SUM A(i,j)∗b(j) FOR ALL j Equivalent infix notation: A ∗ b
Page: (matrix)RightMult, Next: LUdecomp, Prev: LeftMult, Up: Top Index

SUBROUTINE RightMult(ARRAY(∗) OF number c^,a; ARRAY(∗,∗) OF number B)

Computes the right-hand product of vector <a> by matrix <B>, that is c(j)=SUM a(i)∗B(i,j) FOR ALL i Equivalent infix notation: a ∗ B

SUBROUTINE RightMult2(ARRAY(∗) OF COMPLEX c^,a; ARRAY(∗,∗) OF COMPLEX B)

Computes CONJG(a)∗B Equivalent infix notation: a | B
Page: (matrix)LUdecomp, Next: LeftLUDiv, Prev: RightMult, Up: Top Index

SUBROUTINE LUdecomp(POINTER TO ARRAY(∗,∗) OF number A)

Computes the LU decomposition of (square or banded) matrix A in place.

FUNCTION LU(A)

Returns the LU decomposition of A, which remains untouched.
Page: (matrix)LeftLUDiv, Next: RightLUDiv, Prev: LUdecomp, Up: Top Index

SUBROUTINE LeftLUDiv(POINTER TO ARRAY(∗) OF number x; ARRAY(∗,∗) OF number A; ARRAY(∗) OF number t)

Computes the left-hand division of vector <t> by the previously LU-decomposed matrix <A>, that is A^-1∗t. A must have been preventively treated with either LUdecomp or PLU. Equivalent infix notation: A \ t
Page: (matrix)RightLUDiv, Next: Lanczos, Prev: LeftLUDiv, Up: Top Index

SUBROUTINE RightLUDiv(ARRAY(∗) OF number x^,t; ARRAY(∗,∗) OF number A)

Computes the right-hand division of vector <t> by the previously LU-decomposed matrix <A>, that is t∗A^-1. A must have been preventively treated with either LUdecomp or PLU. Equivalent infix notation: t / A
Page: (matrix)Lanczos, Next: PLU, Prev: RightLUDiv, Up: Top Index
SUBROUTINE Lanczos(POINTER TO ARRAY(∗) OF number x SUBROUTINE[ARRAY(∗) OF number v2^,v1] A,AT ARRAY(∗) OF number y1; REAL eps) SUBROUTINE Lanczos(POINTER TO ARRAY(∗) OF number x ARRAY(∗,∗) OF number M ARRAY(∗) OF number y1; REAL eps)
Page: (matrix)PLU, Next: INVERT, Prev: Lanczos, Up: Top Index

POINTER TO INVMAT FUNCTION PLU(ARRAY(∗,∗) OF number m)

Computes the LU decomposition of (necessarily square) matrix A with pivoting. Returns an appropriate INVMAT compound variable containing the LU decomposition of A, which can be passed to either LeftLUDiv or RightLUDiv and must be explicitly freed by FREE:(cpl)NEW. once no longer needed.
Page: (matrix)INVERT, Next: DET, Prev: PLU, Up: Top Index

SUBROUTINE INVERT(ARRAY(∗,∗) OF number mat^, RESULT^)

Returns the inverse of square matrix <mat> in matrix <RESULT>. Uses PLU internally.

SUBROUTINE INVERT(number m^(∗,∗))

Computes the inverse of square matrix <mat> in place. Uses PLU internally.
Page: (matrix)DET, Prev: INVERT, Next: infix notation, Up: Top Index

number FUNCTION DET(ARRAY(∗,∗) OF number mat)

Returns the determinant of square matrix <mat>. Uses PLU internally.
Page: (matrix)infix notation, Prev: DET, Up: Top Index

Infix vector and matrix operations

and their equivalent (cpl)Einstein convention notation: (In the following examples small letters denote 1D arrays, capital letters 2D arrays. Actual, capitalized or not, names are at the user's discretion.) x ∗ y = x($i)∗y($i) x | y = CONJG[x($i)]∗y($i) y = A ∗ x => y($i) = A($i,$j)∗x($j) y = A | x => y($i) = CONJG[A($i,$j)]∗x($j) y = x ∗ A => y($j) = x($i)∗A($i,$j) y = x | A => y($j) = CONJG[x($i)]∗A($i,$j) C = A ∗ B => C($i,$j) = A($i,$k)∗B($k,$j) C = A | B => C($i,$j) = CONJG[A($i,$k)]∗B($k,$j) x = A \ y => LeftLUDiv(x,A,y) x = y / A => RightLUDiv(x,y,A) C = A \ B => C(∗,$j) = A\B(∗,$j) C = B / A => C($i,∗)=B($i,∗)/A (The last four expressions only make sense if A has been obtained from LUdecomp or PLU; LUdecomp applies to both square and banded matrices.) The above product operations can also be combined with linear-space (cpl)ARRAY operations already provided outside the rbmat and cbmat packages. For more general, or higher-dimensional, index contractions, or just for added clarity, you can always use the (cpl)Einstein convention directly.