Up | Next | Prev | PrevTail | Tail |
This package provides a selection of functions that are useful in the world of linear algebra.
This package provides a selection of functions that are useful in the world of linear algebra. These functions are described alphabetically in subsection 16.36.3 and are labelled 16.36.3.1 to 16.36.3.53. They can be classified into four sections(n.b: the numbers after the dots signify the function label in section 16.36.3).
Contributions to this package have been made by Walter Tietze (ZIB).
add_columns | … | 16.36.3.1 | add_rows | … | 16.36.3.2 |
add_to_columns | … | 16.36.3.3 | add_to_rows | … | 16.36.3.4 |
augment_columns | … | 16.36.3.5 | char_poly | … | 16.36.3.9 |
column_dim | … | 16.36.3.12 | copy_into | … | 16.36.3.14 |
diagonal | … | 16.36.3.15 | extend | ldots | 16.36.3.16 |
find_companion | … | 16.36.3.17 | get_columns | … | 16.36.3.18 |
get_rows | … | 16.36.3.19 | hermitian_tp | … | 16.36.3.21 |
matrix_augment | … | 16.36.3.28 | matrix_stack | … | 16.36.3.30 |
minor | … | 16.36.3.31 | mult_columns | … | 16.36.3.32 |
mult_rows | … | 16.36.3.33 | pivot | … | 16.36.3.34 |
remove_columns | … | 16.36.3.37 | remove_rows | … | 16.36.3.38 |
row_dim | … | 16.36.3.39 | rows_pivot | … | 16.36.3.40 |
stack_rows | … | 16.36.3.43 | sub_matrix | … | 16.36.3.44 |
swap_columns | … | 16.36.3.46 | swap_entries | … | 16.36.3.47 |
swap_rows | … | 16.36.3.48 |
Functions that create matrices.
band_matrix | … | 16.36.3.6 | block_matrix | … | 16.36.3.7 |
char_matrix | … | 16.36.3.8 | coeff_matrix | … | 16.36.3.11 |
companion | … | 16.36.3.13 | hessian | … | 16.36.3.22 |
hilbert | … | 16.36.3.23 | mat_jacobian | … | 16.36.3.24 |
jordan_block | … | 16.36.3.25 | make_identity | … | 16.36.3.27 |
random_matrix | … | 16.36.3.36 | toeplitz | … | 16.36.3.50 |
Vandermonde | … | 16.36.3.52 | Kronecker_Product | … | 16.36.3.53 |
char_poly | … | 16.36.3.9 | cholesky | … | 16.36.3.10 |
gram_schmidt | … | 16.36.3.20 | lu_decom | … | 16.36.3.26 |
pseudo_inverse | … | 16.36.3.35 | simplex | … | 16.36.3.41 |
svd | … | 16.36.3.45 | triang_adjoint | … | 16.36.3.51 |
There is a separate NORMFORM[1] package for computing the following matrix normal forms in REDUCE:
smithex, smithex_int, frobenius, ratjordan, jordansymbolic, jordan.
matrixp | … | 16.36.3.29 | squarep | … | 16.36.3.42 |
symmetricp | … | 16.36.3.49 |
In the examples the matrix will be
=
Throughout is used to indicate the identity matrix and
T to indicate the transpose of
the matrix
.
If you have not used matrices within REDUCE before then the following may be helpful.
Initialisation of matrices takes the following syntax:
mat1 := mat((a,b,c),(d,e,f),(g,h,i));
will produce
mat1 :=
The (i,j)th entry can be accessed by:
mat1(i,j);
The package is loaded by:
load_package linalg;
add_columns(,c1,c2,expr);
![]() | :- | a matrix. |
c1, c2 | :- | positive integers. |
expr | :- | a scalar expression. |
Synopsis:
add_columns replaces column c2 of by expr ∗ column(
,c1) +
column(
,c2).
add_rows performs the equivalent task on the rows of .
Examples:
add_columns( ![]() | = | ![]() |
add_rows( ![]() | = | ![]() |
Related functions:
add_to_columns, add_to_rows, mult_columns, mult_rows.
see: add_columns.
add_to_columns(,column_list,expr);
![]() | :- | a matrix. |
column_list | :- | a positive integer or a list of positive integers. |
expr | :- | a scalar expression. |
Synopsis:
add_to_columns adds expr to each column specified in column_list of
.
add_to_rows performs the equivalent task on the rows of .
Examples:
add_to_columns( ![]() | = | ![]() |
add_to_rows( ![]() | = | ![]() |
Related functions:
add_columns, add_rows, mult_rows, mult_columns.
see: add_to_columns.
augment_columns(,column_list);
![]() | :- | a matrix. |
column_list | :- | either a positive integer or a list of positive integers. |
Synopsis:
augment_columns gets hold of the columns of specified in column_list and
sticks them together.
stack_rows performs the same task on rows of .
Examples:
augment_columns( ![]() | = | ![]() |
stack_rows( ![]() | = | ![]() |
Related functions:
get_columns, get_rows, sub_matrix.
band_matrix(expr_list,square_size);
expr_list | :- | either a single scalar expression or a list of an odd number of scalar expressions. |
square_size | :- | a positive integer. |
Synopsis:
band_matrix creates a square matrix of dimension square_size. The diagonal consists of the middle expr of the expr_list. The expressions to the left of this fill the required number of sub-diagonals and the expressions to the right the super-diagonals.
Examples:
band_matrix({x,y,z},6) | = | ![]() |
Related functions:
diagonal.
block_matrix(r,c,matrix_list);
r,c | :- | positive integers. |
matrix_list | :- | a list of matrices. |
Synopsis:
block_matrix creates a matrix that consists of r × c matrices filled from the matrix_list row-wise.
Examples:
![]() ![]() | ![]() ![]() | ![]() ![]() |
block_matrix(2,3,{ ![]() ![]() ![]() ![]() ![]() ![]() | = | ![]() |
char_matrix(,λ);
![]() | :- | a square matrix. |
λ | :- | a symbol or algebraic expression. |
Synopsis:
char_matrix creates the characteristic matrix of
. This is
= λ
−
.
Examples:
char_matrix( ![]() | = | ![]() |
Related functions:
char_poly.
char_poly(,λ);
![]() | :- | a square matrix. |
λ | :- | a symbol or algebraic expression. |
Synopsis:
char_poly finds the characteristic polynomial of .
This is the determinant of λ−
.
Examples:
char_poly(,x) = x3 − 15 ∗ x2 − 18 ∗ x
Related functions:
char_matrix.
cholesky();
![]() | :- | a positive definite matrix containing numeric entries. |
Synopsis:
cholesky computes the cholesky decomposition of .
It returns {,
} where
is a lower matrix,
is an upper matrix,
=
, and
=
T .
Examples:
=
cholesky( ![]() | = | ![]() |
Related functions:
lu_decom.
coeff_matrix({lin_eqn1,lin_eqn2, …,lin_eqnn}); 12
lin_eqn1,lin_eqn2, …,lin_eqnn | :- | linear equations. Can be of the form equation = number or just equation. |
Synopsis:
coeff_matrix creates the coefficient matrix of the linear equations. It returns
{
,
,
} such that
=
.
Examples:
coeff_matrix({x + y + 4 ∗ z = 10,y + x − z = 20,x + y + 4}) =
column_dim();
![]() | :- | a matrix. |
Synopsis:
column_dim finds the column dimension of .
row_dim finds the row dimension of .
Examples:
column_dim() = 3
companion(poly,x);
poly | :- | a monic univariate polynomial in x. |
x | :- | the variable. |
Synopsis:
companion creates the companion matrix of poly.
This is the square matrix of dimension n, where n is the degree of poly w.r.t. x. The
entries of are:
(i,n) = −coeffn(poly,x,i− 1) for i = 1,…,n,
(i,i− 1) = 1
for i = 2,…,n and the rest are 0.
Examples:
companion(x4 + 17 ∗ x3 − 9 ∗ x2 + 11,x) | = | ![]() |
Related functions:
find_companion.
copy_into(,
,r,c);
![]() ![]() | :- | matrices. |
r,c | :- | positive integers. |
Synopsis:
copy_into copies matrix into
with
(1,1) at
(r,c).
Examples:
=
copy_into( ![]() ![]() | = | ![]() |
Related functions:
augment_columns, extend, matrix_augment, matrix_stack, stack_rows, sub_matrix.
diagonal({mat1,mat2, …,matn});13
mat1,mat2, …,matn | :- | each can be either a scalar expr or a square matrix. |
Synopsis:
diagonal creates a matrix that contains the input on the diagonal.
Examples:
=
diagonal({ ![]() ![]() | = | ![]() |
Related functions:
jordan_block.
extend(,r,c,expr);
![]() | :- | a matrix. |
r, c | :- | positive integers. |
expr | :- | algebraic expression or symbol. |
Synopsis:
extend returns a copy of that has been extended by r rows and c columns. The
new entries are made equal to expr.
Examples:
extend( ![]() | = | ![]() |
Related functions:
copy_into, matrix_augment, matrix_stack, remove_columns, remove_rows.
find_companion(,x);
![]() | :- | a matrix. |
x | :- | the variable. |
Synopsis:
Given a companion matrix, find_companion finds the polynomial from which it was made.
Examples:
=
find_companion(,x) = x4 + 17 ∗ x3 − 9 ∗ x2 + 11
Related functions:
companion.
get_columns(,column_list);
![]() | :- | a matrix. |
c | :- | either a positive integer or a list of positive integers. |
Synopsis:
get_columns removes the columns of specified in column_list and returns
them as a list of column matrices.
get_rows performs the same task on the rows of .
Examples:
get_columns( ![]() | = | ![]() |
get_rows( ![]() | = | ![]() |
Related functions:
augment_columns, stack_rows, sub_matrix.
see: get_columns.
gram_schmidt({vec1,vec2, …,vecn}); 14
vec1,vec2, …,vecn | :- | linearly-independent vectors. Each vector must be written as a list, eg:{1,0,0}. |
Synopsis:
gram_schmidt performs the Gram-Schmidt orthonormalisation on the input vectors. It returns a list of orthogonal normalised vectors.
Examples:
gram_schmidt({{1,0,0},{1,1,0},{1,1,1}}) = {{1,0,0},{0,1,0},{0,0,1}}
gram_schmidt({{1,2},{3,4}}) = {{,
},{
,
}}
hermitian_tp();
![]() | :- | a matrix. |
Synopsis:
hermitian_tp computes the hermitian transpose of .
This is a matrix in which the (i,j)th entry is the conjugate of the (j,i)th entry of
.
Examples:
=
hermitian_tp( ![]() | = | ![]() |
Related functions:
tp15 .
hessian(expr,variable_list);
expr | :- | a scalar expression. |
variable_list | :- | either a single variable or a list of variables. |
Synopsis:
hessian computes the hessian matrix of expr w.r.t. the varibles in variable_list.
This is an n × n matrix where n is the number of variables and the (i,j)th entry is df(expr,variable_list(i),variable_list(j)).
Examples:
hessian(x ∗ y ∗ z + x2,{w,x,y,z}) | = | ![]() |
Related functions:
df16 .
hilbert(square_size,expr);
square_size | :- | a positive integer. |
expr | :- | an algebraic expression. |
Synopsis:
hilbert computes the square hilbert matrix of dimension square_size.
This is the symmetric matrix in which the (i,j)th entry is 1∕(i + j −expr).
Examples:
hilbert(3,y + x) | = | ![]() |
mat_jacobian(expr_list,variable_list);
expr_list | :- | either a single algebraic expression or a list of algebraic expressions. |
variable_list | :- | either a single variable or a list of variables. |
Synopsis:
mat_jacobian computes the jacobian matrix of expr_list w.r.t. variable_list.
This is a matrix whose (i,j)th entry is df(expr_list(i),variable_list(j)). The matrix is n × m where n is the number of variables and m the number of expressions.
Examples:
mat_jacobian({x4,x ∗ y2,x ∗ y ∗ z3},{w,x,y,z}) =
Related functions:
hessian, df17 .
NOTE: The function mat_jacobian used to be called just "jacobian" however us of that name was in conflict with another Reduce package.
jordan_block(expr,square_size);
expr | :- | an algebraic expression or symbol. |
square_size | :- | a positive integer. |
Synopsis:
jordan_block computes the square jordan block matrix of dimension
square_size.
The entries of are:
(i,i) = expr for i = 1,…,n,
(i,i + 1) = 1 for
i = 1,…,n − 1, and all other entries are 0.
Examples:
jordan_block(x,5) | = | ![]() |
Related functions:
diagonal, companion.
lu_decom();
![]() | :- | a matrix containing either numeric entries or imaginary entries with numeric coefficients. |
Synopsis:
lu_decom performs LU decomposition on , ie: it returns {
,
} where
is a lower
diagonal matrix,
an upper diagonal matrix and
=
.
caution:
The algorithm used can swap the rows of during the calculation. This means that
does not equal
but a row equivalent of it. Due to this, lu_decom returns {
,
,vec}.
The call convert(
,vec) will return the matrix that has been decomposed, ie:
=
convert(
,vec).
Examples:
=
lu := lu_decom( ![]() | = | ![]() |
first lu * second lu | = | ![]() |
convert( ![]() | = | ![]() |
=
first lu * second lu | = | ![]() |
convert(P,third lu) | = | ![]() |
Related functions:
cholesky.
make_identity(square_size);
square_size | :- | a positive integer. |
Synopsis:
make_identity creates the identity matrix of dimension square_size.
Examples:
make_identity(4) | = | ![]() |
Related functions:
diagonal.
matrix_augment({mat1,mat2, …,matn});18
mat1,mat2, …,matn | :- | matrices. |
Synopsis:
matrix_augment sticks the matrices in matrix_list together horizontally.
matrix_stack sticks the matrices in matrix_list together vertically.
Examples:
matrix_augment({ ![]() ![]() | = | ![]() |
matrix_stack({ ![]() ![]() | = | ![]() |
Related functions:
augment_columns, stack_rows, sub_matrix.
matrixp(test_input);
test_input | :- | anything you like. |
Synopsis:
matrixp is a boolean function that returns t if the input is a matrix and nil otherwise.
Examples:
matrixp() = t
matrixp(doodlesackbanana) = nil
Related functions:
squarep, symmetricp.
see: matrix_augment.
minor(,r,c);
![]() | :- | a matrix. |
r, c | :- | positive integers. |
Synopsis:
minor computes the (r,c)th minor of .
This is created by removing the rth row and the cth column from .
Examples:
minor( ![]() | = | ![]() |
Related functions:
remove_columns, remove_rows.
mult_columns(,column_list,expr);
![]() | :- | a matrix. |
column_list | :- | a positive integer or a list of positive integers. |
expr | :- | an algebraic expression. |
Synopsis:
mult_columns returns a copy of in which the columns specified in column_list
have been multiplied by expr.
mult_rows performs the same task on the rows of .
Examples:
mult_columns( ![]() | = | ![]() |
mult_rows( ![]() | = | ![]() |
Related functions:
add_to_columns, add_to_rows.
see: mult_columns.
pivot(,r,c);
![]() | :- | a matrix. |
r,c | :- | positive integers such that ![]() |
Synopsis:
pivot pivots about its (r,c)th entry.
To do this, multiples of the r’th row are added to every other row in the matrix.
This means that the c’th column will be 0 except for the (r,c)’th entry.
Examples:
pivot( ![]() | = | ![]() |
Related functions:
rows_pivot.
pseudo_inverse();
![]() | :- | a matrix. |
Synopsis:
pseudo_inverse, also known as the Moore-Penrose inverse, computes the
pseudo inverse of .
Given the singular value decomposition of , i.e:
=
∑
T , then the pseudo
inverse
−1 is defined by
−1 =
T ∑
−1
.
Thus ∗pseudo_inverse(
) =
.
Examples:
pseudo_inverse( ![]() | = | ![]() |
Related functions:
svd.
random_matrix(r,c,limit);
r,c, limit | :- | positive integers. |
Synopsis:
random_matrix creates an r × c matrix with random entries in the range −limit < entry < limit.
switches:
imaginary | :- | if on, then matrix entries are x + iy where −limit < x,y < limit. |
not_negative | :- | if on then 0 < entry < limit. In the imaginary case we have 0 < x,y < limit. |
only_integer | :- | if on then each entry is an integer. In the imaginary case x,y are integers. |
symmetric | :- | if on then the matrix is symmetric. |
upper_matrix | :- | if on then the matrix is upper triangular. |
lower_matrix | :- | if on then the matrix is lower triangular. |
Examples:
random_matrix(3,3,10) | = | ![]() |
on only_integer, not_negative, upper_matrix, imaginary;
random_matrix(4,4,10) | = | ![]() |
remove_columns(,column_list);
![]() | :- | a matrix. |
column_list | :- | either a positive integer or a list of positive integers. |
Synopsis:
remove_columns removes the columns specified in column_list from
.
remove_rows performs the same task on the rows of .
Examples:
remove_columns( ![]() | = | ![]() |
remove_rows( ![]() | = | ![]() |
Related functions:
minor.
see: remove_columns.
see: column_dim.
rows_pivot(,r,c,{row_list});
![]() | :- | a matrix. |
r,c | :- | positive integers such that ![]() |
row_list | :- | positive integer or a list of positive integers. |
Synopsis:
rows_pivot performs the same task as pivot but applies the pivot only to the rows specified in row_list.
Examples:
=
rows_pivot( ![]() | = | ![]() |
Related functions:
pivot.
simplex(max/min,objective function,{linear inequalities},[{bounds}]);
max/min | :- | either max or min (signifying maximise and minimise). |
objective function | :- | the function you are maximising or minimising. |
linear inequalities | :- | the constraint inequalities. Each one must be of the form sum of variables (<=,=,>=) number. |
bounds | :- | bounds on the variables as specified for the LP file format. Each bound is of one of the forms l ≤ v, v ≤ u, or l ≤ v ≤ u, where v is a variable and l, u are numbers or infinity or -infinity |
Synopsis:
simplex applies the revised simplex algorithm to find the optimal(either maximum or minimum) value of the objective function under the linear inequality constraints.
It returns {optimal value,{ values of variables at this optimal}}.
The {bounds} argument is optional and admissible only when the switch fastsimplex is on, which is the default.
Without a {bounds} argument, the algorithm implies that all the variables are non-negative.
Examples:
simplex(max,x + y,{x >= 10,y >= 20,x + y <= 25});
***** Error in simplex: Problem has no feasible solution.
simplex(max,10x+5y+5.5z,{5x+3z <= 200,x+0.1y+0.5z <= 12,
0.1x + 0.2y + 0.3z <= 9,30x + 10y + 50z <= 1500});
{525.0,{x = 40.0,y = 25.0,z = 0}}
squarep();
![]() | :- | a matrix. |
Synopsis:
squarep is a boolean function that returns t if the matrix is square and nil otherwise.
Examples:
=
squarep() = t
squarep() = nil
Related functions:
matrixp, symmetricp.
see: augment_columns.
sub_matrix(,row_list,column_list);
![]() | :- | a matrix. |
row_list, column_list | :- | either a positive integer or a list of positive integers. |
Synopsis:
sub_matrix produces the matrix consisting of the intersection of the rows specified in row_list and the columns specified in column_list.
Examples:
sub_matrix( ![]() | = | ![]() |
Related functions:
augment_columns, stack_rows.
svd();
![]() | :- | a matrix containing only numeric entries. |
Synopsis:
svd computes the singular value decomposition of .
It returns {,∑
,
} where
=
∑
T and ∑
= diag(σ1,…,σn).σi for
i = (1…n) are the singular values of
.
n is the column dimension of .
The singular values of are the non-negative square roots of the eigenvalues of
T
.
and
are such that
T =
T =
T
=
n.
Examples:
=
swap_columns(,c1,c2);
![]() | :- | a matrix. |
c1,c1 | :- | positive integers. |
Synopsis:
swap_columns swaps column c1 of with column c2.
swap_rows performs the same task on 2 rows of .
Examples:
swap_columns( ![]() | = | ![]() |
Related functions:
swap_entries.
swap_entries(,{r1,c1},{r2,c2});
![]() | :- | a matrix. |
r1,c1,r2,c2 | :- | positive integers. |
Synopsis:
swap_entries swaps (r1,c1) with
(r2,c2).
Examples:
swap_entries( ![]() | = | ![]() |
Related functions:
swap_columns, swap_rows.
see: swap_columns.
symmetricp();
![]() | :- | a matrix. |
Synopsis:
symmetricp is a boolean function that returns t if the matrix is symmetric and nil otherwise.
Examples:
=
symmetricp() = nil
symmetricp() = t
Related functions:
matrixp, squarep.
toeplitz({expr1,expr2, …,exprn}); 19
expr1,expr2, …,exprn | :- | algebraic expressions. |
Synopsis:
toeplitz creates the toeplitz matrix from the expression list.
This is a square symmetric matrix in which the first expression is placed on the diagonal and the i’th expression is placed on the (i-1)’th sub and super diagonals.
It has dimension n where n is the number of expressions.
Examples:
toeplitz({w,x,y,z}) | = | ![]() |
triang_adjoint();
![]() | :- | a matrix. |
Synopsis:
triang_adjoint computes the triangularizing adjoint of matrix
due to the
algorithm of Arne Storjohann.
is lower triangular matrix and the resulting matrix
of
∗
=
is upper triangular with the property that the i-th entry in the
diagonal of
is the determinant of the principal i-th submatrix of the matrix
.
Examples:
triang_adjoint( ![]() | = | ![]() |
![]() ![]() | = | ![]() |
vandermonde({expr1,expr2, …,exprn}); 19
expr1,expr2, …,exprn | :- | algebraic expressions. |
Synopsis:
Vandermonde creates the Vandermonde matrix from the expression list. This is the square matrix in which the (i,j)th entry is expri(j−1). It has dimension n, where n is the number of expressions.
Examples:
vandermonde({x,2 ∗ y,3 ∗ z}) | = | ![]() |
kronecker_product(M1,M2)
M1,M2 | :- | Matrices |
Synopsis:
kronecker_product creates a matrix containing the Kronecker product (also called direct product or tensor product) of its arguments.
Examples:
![]() |
By turning the fast_la switch on, the speed of the following functions will be increased:
add_columns | add_rows | augment_columns | column_dim |
copy_into | make_identity | matrix_augment | matrix_stack |
minor | mult_column | mult_row | pivot |
remove_columns | remove_rows | rows_pivot | squarep |
stack_rows | sub_matrix | swap_columns | swap_entries |
swap_rows | symmetricp |
The increase in speed will be insignificant unless you are making a significant number(i.e: thousands) of calls. When using this switch, error checking is minimised. This means that illegal input may give strange error messages. Beware.
Many of the ideas for this package came from the Maple[3] Linalg package [4].
The algorithms for cholesky, lu_decom, and svd are taken from the book Linear Algebra - J.H. Wilkinson & C. Reinsch[5].
The gram_schmidt code comes from Karin Gatermann’s Symmetry package[6] for REDUCE.
[1] Matt Rebbeck: NORMFORM: A REDUCE package for the computation of various matrix normal forms. ZIB, Berlin. (1993)
[2] Anthony C. Hearn: REDUCE User’s Manual 3.6. RAND (1995)
[3] Bruce W. Char…[et al.]: Maple (Computer Program). Springer-Verlag (1991)
[4] Linalg - a linear algebra package for Maple[3].
[5] J. H. Wilkinson & C. Reinsch: Linear Algebra (volume II). Springer-Verlag (1971)
[6] Karin Gatermann: Symmetry: A REDUCE package for the computation of linear representations of groups. ZIB, Berlin. (1992)
Up | Next | Prev | PrevTail | Front |