matrix2.icn: Procedures for matrix transposition and scalar multiplication

link matrix2
November 1, 2005; Arthur C. Eschenlauer
This file is in the public domain.

transpose_matrix(M) : L  - produces a matrix R that is the transpose of M:
                              R[j][i] = M[i][j]

numeric_matrix(M) : L    - produces a matrix R that is a copy of M except
                           each element has been subjected to the
                           numeric(x) function; if numeric fails for any
                           element, numeric_matrix fails:
                              R[i][j] = numeric(M[i][j])

scale_matrix(M,mult) : L - produces a new matrix R each of whose elements
                           is mult times larger than its peer in M:
                               R[i][j] := mult * M[i][j]
scale_matrix(mult,M) : L - is a synonym for scale_matrix(M,mult).

floor_matrix(M,min) : L  - produces a matrix R that is a copy of M except
                           each element is increased to min if necessary:
                               R[i][j] := min <= M[i][j] | min
floor_matrix(min,M) : L  - is a synonym for floor_matrix(M,min).

ceil_matrix(M,max) : L   - produces a matrix R that is a copy of M except
                           each element is increased to max if necessary:
                               R[i][j] := max <= M[i][j] | max
ceil_matrix(max,M) : L   - is a synonym for ceil_matrix(M,max).

sumsquares_matrix(M) : n - produces the sum of the squares
                           of all terms in a matrix
                               sum(for every i,j) (M[i][j])^2

sumsquaresdiff_matrix(M1,M2) : n - produces the sum of the squares of all
                           terms in the difference between two matrices
                               sum(for every i,j) (M1[i][j] - M2[i][j])^2

normalize_rows(M,t) : L  - produce a row-scaled matrix such that,
                           for every row i, the sum of the values in
                           all columns is 1
                               R[i][j] /:= sum(for every J) M[i][J]
                           t is a required minimum magnitude
                           for row sums to avoid divide-by-zero errors
normalize_rows(t,M) : L  - synonym for normalize_rows(M,t)

normalize_columns(M,t) : L - produce a column-scaled matrix such that,
                             for every column i, the sum of the values
                             in all rows is 1
                             such that their sum is 1
                               R[i][j] /:= sum(for every I) M[I][j]
                             t is a required minimum magnitude for
                             column sums to avoid divide-by-zero errors
normalize_columns(t,M) : L - synonym for normalize_columns(M,t)

sprintf_matrix(f,M)      - produces a matrix R of strings whose elements
                           are formatted (by the IPL sprintf routine)
                           from the elements of M:
                               R[i][j] := sprintf(f,M[i,j])

Source code | Program Library Page | Icon Home Page