File matrix_util.icn

Summary

Provides utilities for creating and manipulating matrices

Author: Kevin Wampler (kevin@tapestry.tucson.az.us)
Minor adjustments (cosmetic) by Steve Wampler (sbw@tapestry.tucson.az.us)

This file is in the public domain.

Procedures:
m_add, m_binop, m_col, m_colswap, m_constant, m_copy, m_divide, m_identity, m_inverse, m_linearSolve, m_lupDecomposition, m_lupSolve, m_multiply, m_negative, m_rowswap, m_subtract, m_transpose, m_unaryop, m_write

Imports:
lang

This file is part of the util package.

Source code.

Details
Procedures:

m_add(M1, M2)

Parameters:
M1
first matrix
M2
second matrix
Returns:
M1+M2


m_binop(M1, M1, op)

Parameters:
M1
first matrix
M2
second matrix
op
binary operation to invoke
Returns:
M1 op M2, with op defaulting to proc("+",2)

Generic binary operation across two matrices.


m_col(M, a)

Parameters:
M
matrix
a
column to return from M
Returns:
column a of M


m_colswap(M, a, b)

Parameters:
M
matrix
a
first column to swap
b
second column to swap

Swaps columns a and b of M


m_constant(m, n, x:0)

Parameters:
m
number of rows
n
number of columns
x
initial value of every element
Returns:
a m x n matrix with x everywhere


m_copy(M)

Parameter:
M
a matrix
Returns:
a copy of matrix M


m_divide(M1, M2, addfun, subfun, mulfun, divfun, addident, mulident, invertMetric)

Returns:
a matrix X such that M2*X = M1

Additional optional arguments allow you to customize the operation by overriding various functions and constants used internally.


m_identity(m, n, zero:0, one:1)

Parameters:
m
number of rows
n
number of columns
zero
(optional) can be used in place of 0.0
one
(optional) can be used in place of 1.0
Returns:
mXn identify matrix

Creates a m x n matrix with ones on the diagonal and zeros everywhere else


m_inverse(M, addfun, subfun, mulfun, divfun, addident, mulident, invertMetric)

Returns:
the (multiplicative) inverse of M

Additional optional arguments allow you to customize the operation by overriding various functions and constants used internally.


m_linearSolve(A, b, addfun, subfun, mulfun, divfun, addident, mulident, invertMetric)

Returns:
the solution x to A*x = b

Additional optional arguments allow you to customize the operation by overriding various functions and constants used internally.


m_lupDecomposition(M, subfcn, mulfcn, divfcn, invertMetric, addident:0, mulident:1)

Returns:
the LUP decomposition of M, fails if M is singular

The result is returned as a list [L, U, p] of matrices such that P*M = L*U, and p is a list representing the permutation to create P.

Additional optional arguments allow you to customize the operation by overriding various functions and constants used internally.


m_lupSolve(L, U, p, b, addfun, subfun, mulfun, divfun, addident:0)

Returns:
the solution x to A*x = b where the LUP decomposition of A is [L,U,p]

Additional optional arguments allow you to customize the operation by overriding various functions and constants used internally.


m_multiply(M1, M2, addident:0, addfcn, mulfcn)

Parameters:
M1
first matrix
M2
second matrix
addident
(optional) additive identify replacement
addfcn
(optional) addition operation replacement
mulfcn
(optional) multiplication operation replacement
Returns:
M1*M2


m_negative(M)

Parameter:
M
matrix
Returns:
-M


m_rowswap(M, a, b)

Parameters:
M
matrix
a
first row to swap
b
second row to swap

Swaps rows a and b of M


m_subtract(M1, M2)

Parameters:
M1
first matrix
M2
second matrix
Returns:
M1-M2


m_transpose(M)

Parameter:
M
matrix
Returns:
the transpose of M


m_unaryop(M, op)

Parameters:
M
matrix
op
unary operation to invoke
Returns:
op M, with op defaulting to proc("-",1)

Generic unary operation across a matrix.


m_write(args)

Output matrices.

A file argument changes output of subsequent arguments to that file (default is &output). String arguments are output as they appear. Matrices are output one row per line of output followed by a blank line.

Matrices and output files



This page produced by UniDoc on 2021/04/15 @ 23:59:54.