REDUCE

16.37 LINALG: Linear algebra package

This package provides a selection of functions that are useful in the world of linear algebra.

Author: Matt Rebbeck.

16.37.1 Introduction

This package provides a selection of functions that are useful in the world of linear algebra. These functions are described alphabetically in subsection 16.37.3 and are labelled 16.37.3.1 to 16.37.3.53. They can be classified into four sections(n.b: the numbers after the dots signify the function label in section 16.37.3).

Contributions to this package have been made by Walter Tietze (ZIB).

16.37.1.1 Basic matrix handling

add_columns 16.37.3.1 add_rows 16.37.3.2
add_to_columns 16.37.3.3 add_to_rows 16.37.3.4
augment_columns16.37.3.5 char_poly 16.37.3.9
column_dim 16.37.3.12copy_into 16.37.3.14
diagonal 16.37.3.15extend ldots16.37.3.16
find_companion 16.37.3.17get_columns 16.37.3.18
get_rows 16.37.3.19hermitian_tp 16.37.3.21
matrix_augment 16.37.3.28matrix_stack 16.37.3.30
minor 16.37.3.31mult_columns16.37.3.32
mult_rows 16.37.3.33pivot 16.37.3.34
remove_columns 16.37.3.37remove_rows 16.37.3.38
row_dim 16.37.3.39rows_pivot 16.37.3.40
stack_rows 16.37.3.43sub_matrix 16.37.3.44
swap_columns 16.37.3.46swap_entries 16.37.3.47
swap_rows 16.37.3.48

16.37.1.2 Constructors

Functions that create matrices.

band_matrix 16.37.3.6 block_matrix 16.37.3.7
char_matrix 16.37.3.8 coeff_matrix 16.37.3.11
companion 16.37.3.13hessian 16.37.3.22
hilbert 16.37.3.23mat_jacobian 16.37.3.24
jordan_block 16.37.3.25make_identity 16.37.3.27
random_matrix16.37.3.36toeplitz 16.37.3.50
Vandermonde 16.37.3.52Kronecker_Product16.37.3.53

16.37.1.3 High level algorithms

char_poly 16.37.3.9 cholesky 16.37.3.10
gram_schmidt 16.37.3.20lu_decom 16.37.3.26
pseudo_inverse16.37.3.35simplex 16.37.3.41
svd 16.37.3.45triang_adjoint16.37.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.

16.37.1.4 Predicates

matrixp 16.37.3.29squarep16.37.3.42
symmetricp16.37.3.49

Note on examples:

In the examples the matrix A will be

     (        )
       1  2  3
A =  ( 4  5  6)
       7  8  9

Notation

Throughout I is used to indicate the identity matrix and AT to indicate the transpose of the matrix A.

16.37.2 Getting started

If you have not used matrices within REDUCE before then the following may be helpful.

Creating matrices

Initialisation of matrices takes the following syntax:

mat1 := mat((a,b,c),(d,e,f),(g,h,i));

will produce

mat1 := ( a  b  c)
( d  e  f)

  g  h  i

Getting at the entries

The (i,j)th entry can be accessed by:

mat1(i,j);

Loading the linear_algebra package

The package is loaded by:

load_package linalg;

16.37.3 What’s available

16.37.3.1 add_columns, add_rows
Syntax:

add_columns(A,c1,c2,expr);
A :-a matrix.
c1, c2 :- positive integers.
expr :-a scalar expression.
Synopsis:

add_columns replaces column c2 of A by
expr*column(A,c1) + column(A,c2).
add_rows performs the equivalent task on the rows of A.
Examples:
add_columns(A,1,2,x) = (              )
  1   x + 2   3
( 4 4 *x + 5  6)
  7 7 *x + 8  9
add_rows(A,2,3,5) = (           )
  1   2   3
( 4   5   6 )
  27  33  39
Related functions:

add_to_columns, add_to_rows, mult_columns, mult_rows.

16.37.3.2 add_rows

See: add_columns.

16.37.3.3 add_to_columns, add_to_rows
Syntax:

add_to_columns(A,column_list,expr);
A :-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 A.

add_to_rows performs the equivalent task on the rows of A.

Examples:
add_to_columns(A,{1,2},10) = (          )
  11  12  3
( 14  15  6)
  17  18  9
add_to_rows(A,2,-x) = (                        )
     1       2       3
( - x+  4 - x + 5  - x + 6)
     7       8       9
Related functions:

add_columns, add_rows, mult_rows, mult_columns.

16.37.3.4 add_to_rows

See: add_to_columns.

16.37.3.5 augment_columns, stack_rows
Syntax:

augment_columns(A,column_list);
A :-a matrix.
column_list :- either a positive integer or a list of positive integers.
Synopsis:

augment_columns gets hold of the columns of A specified in column_list and sticks them together.
stack_rows performs the same task on rows of A.
Examples:
augment_columns(A,{1,2}) = ( cc1  2)
(      )
  4   5
  7   8
stack_rows(A,{1,3}) = (        )
  1  2  3
  7  8  9
Related functions:

get_columns, get_rows, sub_matrix.

16.37.3.6 band_matrix
Syntax:

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) = (                 )
 y   z  0  0  0  0
||x   y  z  0  0  0||
||0  x   y  z  0  0||
||0   0  x  y  z  0||
(0   0  0  x  y  z)
 0   0  0  0  x  y

Related functions:

diagonal.

16.37.3.7 block_matrix
Syntax:

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:
B = (1   0)
  0  1,C = (5)
 5,D = (22  33 )
 44  55
block_matrix(2,3,{B,C,D,D,C,B}) = ( 1   0  5  22  33)
| 0   1  5  44  55|
|(                 |)
 22  33  5   1   0
 44  55  5   0   1

16.37.3.8 char_matrix
Syntax:

char_matrix(A);
A:-a square matrix.
λ :-a symbol or algebraic expression.
Synopsis:

char_matrix creates the characteristic matrix C of A. This is C = λI-A.
Examples:

char_matrix(A,x) = ( x - 1   - 2   - 3 )
(  - 4   x- 5   - 6 )

   - 7    - 8  x - 9

Related functions:

char_poly.

16.37.3.9 char_poly
Syntax:

char_poly(A);
A:-a square matrix.
λ :-a symbol or algebraic expression.
Synopsis:

char_poly finds the characteristic polynomial of A.

This is the determinant of λI-A.

Examples:

char_poly(A,x) = x3 - 15 * x2 - 18 * x
Related functions:

char_matrix.

16.37.3.10 cholesky
Syntax:

cholesky(A);
A:-a positive definite matrix containing numeric entries.
Synopsis:

cholesky computes the cholesky decomposition of A.

It returns {L,U} where L is a lower matrix, U is an upper matrix,
A = LU, and U = LT .

Examples:

F = (        )
  1  1  0
( 1  3  1)
  0  1  1
cholesky(F) = (| ( 1   0   0 )   (1   1    0 ) )|
{      √ --       |   √ -- √1-| }
| ( 1   12  01 ) , (0    2    2) |
(   0  √2-  √2-    0   0   √12-  )
Related functions:

lu_decom.

16.37.3.11 coeff_matrix
Syntax:

coeff_matrix({lin_eqn1,lin_eqn2, …,lin_eqnn}); 14
lin_eqn1,lin_eqn2, …,lin_eqnn:-

linear equations. Can be of the form equation = number or just equation which is equivalent to equation = 0.

Synopsis:

coeff_matrix creates the coefficient matrix C of the linear equations. It returns {C,X,B} such that CX = B.
Examples:
coeff_matrix({x + y + 4 * z = 10,y + x - z = 20,x + y + 4}) =
( (         )   (  )  (    ) )
{    4  1  1      z     10   }
  ( - 1 1  1)  ,( y) ,( 20 )
(    0  1  1      x     - 4  )

16.37.3.12 column_dim, row_dim
Syntax:

column_dim(A);
A:-a matrix.
Synopsis:

column_dim finds the column dimension of A.
row_dim finds the row dimension of A.
Examples:

column_dim(A) = 3

16.37.3.13 companion
Syntax:

companion(poly,x);
poly:-a monic univariate polynomial in x.
x :-the variable.
Synopsis:

companion creates the companion matrix C of poly.

This is the square matrix of dimension n, where n is the degree of poly w.r.t. x. The entries of C are: C(i,n) = -coeffn(poly,x,i - 1) for i = 1,,n, C(i,i - 1) = 1 for i = 2,,n and the rest are 0.

Examples:

companion(x4 + 17 * x3 - 9 * x2 + 11,x) = ( 0  0  0  - 11)
| 1  0  0   0 |
|(             |)
  0  1  0   9
  0  0  1  - 17

Related functions:

find_companion.

16.37.3.14 copy_into
Syntax:

copy_into(A,B,r,c);
A,B:-matrices.
r,c :-positive integers.
Synopsis:

copy_into copies matrix A into B with A(1,1) at B(r,c).
Examples:

G = (           )
  0  0  0  0
|| 0  0  0  0||
( 0  0  0  0)
  0  0  0  0
copy_into(A,G,1,2) = (           )
  0  1  2  3
| 0  4  5  6|
|( 0  7  8  9|)

  0  0  0  0
Related functions:

augment_columns, extend, matrix_augment, matrix_stack, stack_rows, sub_matrix.

16.37.3.15 diagonal
Syntax:

diagonal({mat1,mat2, …,matn});15
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:

H = (       )
  66  77
  88  99
diagonal({A,x,H}) = ( 1  2  3  0  0   0 )
| 4  5  6  0  0   0 |
|| 7  8  9  0  0   0 ||
||                   ||
|( 0  0  0 x   0   0 |)
  0  0  0  0  66  77
  0  0  0  0  88  99
Related functions:

jordan_block.

16.37.3.16 extend
Syntax:

extend(A,r,c,expr);
A :-a matrix.
r, c :- positive integers.
expr:-algebraic expression or symbol.
Synopsis:

extend returns a copy of A that has been extended by r rows and c columns. The new entries are made equal to expr.
Examples:

extend(A,1,2,x) = (              )
  1  2  3  x  x
|| 4  5  6  x  x||
( 7  8  9  x  x)
  x  x  x  x  x

Related functions:

copy_into, matrix_augment, matrix_stack, remove_columns, remove_rows.

16.37.3.17 find_companion
Syntax:

find_companion(A,x);
A:-a matrix.
x :- the variable.
Synopsis:

Given a companion matrix, find_companion finds the polynomial from which it was made.
Examples:
C = ( 0  0  0 - 11)
| 1  0  0   0 |
|( 0  1  0   9 |)

  0  0  1 - 17
find_companion(C,x) = x4 + 17 * x3 - 9 * x2 + 11
Related functions:

companion.

16.37.3.18 get_columns, get_rows
Syntax:

get_columns(A,column_list);
A:-a matrix.
c :- either a positive integer or a list of positive integers.
Synopsis:

get_columns removes the columns of A specified in column_list and returns them as a list of column matrices.

get_rows performs the same task on the rows of A.

Examples:
get_columns(A,{1,3}) = ({ ( 1)  ( 3) )}
  ( 4) ,( 6)
(            )
    7     9
get_rows(A,2) = {(       )}
  4  5  6
Related functions:

augment_columns, stack_rows, sub_matrix.

16.37.3.19 get_rows

See: get_columns.

16.37.3.20 gram_schmidt
Syntax:

gram_schmidt({vec1,vec2, …,vecn}); 16
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}}) = {{√1--
  5,√2--
  5},{   √--
2*--5-
  5,  √--
---5-
  5}}

16.37.3.21 hermitian_tp
Syntax:

hermitian_tp(A);
A:-a matrix.
Synopsis:

hermitian_tp computes the hermitian transpose of A.

This is a matrix in which the (i,j)th entry is the conjugate of the (j,i)th entry of A.

Examples:

J = (                  )
  i+ 1  i + 2  i+ 3
(   4     5     2  )
    1     i     0
hermitian_tp(J ) = (              )
  - i + 1 4  1
( - i + 2 5  - i)
  - i + 3 2  0
Related functions:

tp17 .

16.37.3.22 hessian
Syntax:

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}) = (           )
  0  0  0  0
|| 0  2  z  y||
( 0  z  0  x)
  0  y  x  0

Related functions:

df18 .

16.37.3.23 hilbert
Syntax:

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) = ( ---1--  --1--- ---1-)
| x+y--12   x+-y1-3  x+y--14|
( x+y-3-  x+y-4- x+y-5)
  x+-y1-4-  x-+1y-5- x+-y1-6-

16.37.3.24 jacobian
Syntax:

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}) =
(                               )
  0  4* x3     0          0
( 0   y2    2* x* y       0     )
  0  y * z3  x* z3   3* x* y *z2
Related functions:

hessian, df19 .

NOTE: The function mat_jacobian used to be called just "jacobian" however us of that name was in conflict with another Reduce package.

16.37.3.25 jordan_block
Syntax:

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 J of dimension square_size.

The entries of J are: J (i,i) = expr for i = 1,,n, J (i,i + 1) = 1 for i = 1,,n - 1, and all other entries are 0.

Examples:

jordan_block(x,5) = ( x  1  0  0  0 )
|               |
|| 0  x  1  0  0 ||
| 0  0  x  1  0 |
( 0  0  0  x  1 )
  0  0  0  0  x

Related functions:

diagonal, companion.

16.37.3.26 lu_decom
Syntax:

lu_decom(A);
A:-a matrix containing either numeric entries or imaginary entries with numeric coefficients.
Synopsis:

lu_decom performs LU decomposition on A, ie: it returns {L,U} where L is a lower diagonal matrix, U an upper diagonal matrix and A = LU.

Caution: The algorithm used can swap the rows of A during the calculation. This means that LU does not equal A but a row equivalent of it. Due to this, lu_decom returns {L,U,vec}. The call convert(A,vec) will return the matrix that has been decomposed, ie: LU = convert(A,vec).

Examples:

K = (         )
( 1   3  5)
 - 4  3  7
  8   6  4

lu := lu_decom(K) =( (                 )   (            )      )
{    8    0      0       1  0.75  0.5       }
  ( - 4   6      0  ) , (0    1   1.5) ,[323]
(    1   2.25  1.1251     0    0    1        )

first lu * second lu = (         )
  8   6  4
(- 4  3  7)
  1   3  5
convert(K,third lu) = ( 8   6  4)
(         )
 - 4  3  7
  1   3  5

P = (i + 1  i+ 2  i+ 3)
(  4     5     2  )

   1     i     0

lu := lu_decom(P) =( (                                     )
{     1       0               0
  (   4   - 4 *i+ 5           0         ) ,
(   i+ 1      3      0.41463 *i+ 2.26829
(                         )       )
(1   i          0         )       }
  0 1  0.19512 *i+  0.24390   ,[323])
  0 0           1

first lu * second lu = (  1     i      0 )
(  4     5      2 )

 i + 1  i+ 2  i+ 3
convert(P,thirdlu) = (  1     i      0 )
(                 )
   4     5      2
 i + 1  i+ 2  i+ 3
Related functions:

cholesky.

16.37.3.27 make_identity
Syntax:

make_identity(square_size);
square_size:-a positive integer.
Synopsis:

make_identity creates the identity matrix of dimension square_size.
Examples:

make_identity(4) = (           )
  1  0  0  0
|| 0  1  0  0||
( 0  0  1  0)
  0  0  0  1

Related functions:

diagonal.

16.37.3.28 matrix_augment, matrix_stack
Syntax:

matrix_augment({mat1,mat2, …,matn});20
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({A,A}) = (                 )
  1  2  3  1  2  3
( 4  4  6  4  5  6)
  7  8  9  7  8  9
matrix_stack({A,A}) = (       )
 1  2  3
|4  5  6|
||7  8  9||
||       ||
|(1  2  3|)
 4  5  6
 7  8  9
Related functions:

augment_columns, stack_rows, sub_matrix.

16.37.3.29 matrixp
Syntax:

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(A) = t

matrixp(doodlesackbanana) = nil

Related functions:

squarep, symmetricp.

16.37.3.30 matrix_stack

See: matrix_augment.

16.37.3.31 minor
Syntax:

minor(A,r,c);
A:-a matrix.
r, c :- positive integers.
Synopsis:

minor computes the (r,c)th minor of A.

This is created by removing the rth row and the cth column from A.

Examples:

minor(A,1,3) = (4   5)
  7  8

Related functions:

remove_columns, remove_rows.

16.37.3.32 mult_columns, mult_rows
Syntax:

mult_columns(A,column_list,expr);
A :-a matrix.
column_list :- a positive integer or a list of positive integers.
expr :-an algebraic expression.
Synopsis:

mult_columns returns a copy of A in which the columns specified in column_list have been multiplied by expr.

mult_rows performs the same task on the rows of A.

Examples:
mult_columns(A,{1,3},x) = (  x    2  3* x)
(              )
  4* x  5  6* x
  7* x  8  9* x
mult_rows(A,2,10) = (           )
  1   2   3
( 40  50  60)
  7   8   9
Related functions:

add_to_columns, add_to_rows.

16.37.3.33 mult_rows

See: mult_columns.

16.37.3.34 pivot
Syntax:

pivot(A,r,c);
A:-a matrix.
r,c:-positive integers such that A(r,c)0.
Synopsis:

pivot pivots A 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(A,2,3) = (             )
  - 1  - 0.5 0
(  4    5    6)
   1    0.5   0

Related functions:

rows_pivot.

16.37.3.35 pseudo_inverse
Syntax:

pseudo_inverse(A);
A:-a matrix containing only real numeric entries.
Synopsis:

pseudo_inverse, also known as the Moore-Penrose inverse, computes the pseudo inverse of A.

Given the singular value decomposition of A, i.e: A = UΣVT , then the pseudo inverse A is defined by A = VΣUT . For the diagonal matrix Σ, the pseudoinverse Σ is computed by taking the reciprocal of only the nonzero diagonal elements.

If A is square and non-singular, then A = A. In general, however, AAA = A, and AAA = A.

Perhaps more importantly, A solves the following least-squares problem: given a rectangular matrix A and a vector b, find the x minimizing Ax - b2, and which, in addition, has minimum 2 (euclidean) Norm, x2. This x is Ab.

Examples:

                                         (             )
                                           - 0.2   0.1
     (1   2  3  4)                       | - 0.05   0.05|
R  =   9  8  7  6  ,  pseudo_inverse(R ) = |(  0.1     0  |)

                                            0.25   - 0.05

Related functions:

svd.

16.37.3.36 random_matrix
Syntax:

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) = (                                )
 - 4.729721  6.987047   7.521383
(- 5.224177  5.797709  - 4.321952 )
 - 9.418455  - 9.94318 - 0.730980
on only_integer, not_negative, upper_matrix, imaginary;
random_matrix(4,4,10) = (2 *i + 5  3* i+ 7  7* i+ 3     6   )
|                                   |
|(   0      2* i+ 5  5* i+ 1  2 *i+ 1|)
    0         0        8        i
    0         0        0     5 *i+ 9

16.37.3.37 remove_columns, remove_rows
Syntax:

remove_columns(A,column_list);
A :-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 A.

remove_rows performs the same task on the rows of A.

Examples:
remove_columns(A,2) = (    )
 1  3
(4  6)
 7  9
remove_rows(A,{1,3}) = (4  5  6)
Related functions:

minor.

16.37.3.38 remove_rows

See: remove_columns.

16.37.3.39 row_dim

See: column_dim.

16.37.3.40 rows_pivot
Syntax:

rows_pivot(A,r,c,{row_list});
A :-a matrix.
r,c :- positive integers such that A(r,c) neq 0.
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:

N = (1  2  3)
|4  5  6|
||7  8  9||
|(       |)
 1  2  3
 4  5  6
rows_pivot(N,2,3,{4,5}) =(                 )
     1    2    3
||    4    5    6  ||
||    7    8    9  ||
( - 0.75  0   0.75 )
  - 0.375  0  0.375
Related functions:

pivot.

16.37.3.41 simplex
Syntax:

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}}

16.37.3.42 squarep
Syntax:

squarep(A);
A:-a matrix.
Synopsis:

squarep is a boolean function that returns t if the matrix is square and nil otherwise.
Examples:
L = (       )
 1  3  5
squarep(A) = t
squarep(L) = nil
Related functions:

matrixp, symmetricp.

16.37.3.43 stack_rows

See: augment_columns.

16.37.3.44 sub_matrix
Syntax:

sub_matrix(A,row_list,column_list);
A :-

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(A,{1,3},{2,3}) = (    )
 2  3
 8  9

Related functions:

augment_columns, stack_rows.

16.37.3.45 svd (singular value decomposition)
Syntax:

svd(A);
A:-a matrix containing only real numeric entries.
Synopsis:

svd computes the singular value decomposition of A. If A is an m × n real matrix of (column) rank r, svd returns the 3-element list {U,Σ,V} where A = UΣVT .

Let k = min(m,n). Then U is m × k, V is n × k, and and Σ = diag(σ1,k), where σi 0 are the singular values of A; only r of these are non-zero. The singular values are the non-negative square roots of the eigenvalues of AT A.

U and V are such that UUT = VVT = VT V = Ik.

Note: there are a number of different definitions of SVD in the literature, in some of which Σ is square and U and V rectangular, as here, but in others U and V are square, and Σ is rectangular.

Examples:

Q = (       )
   1   3
( - 4  3)
   3   6
svd(Q) = ({  ( 0.0236042   0.419897 )  (                )
   (- 0.969049  0.232684 ) ,  4.83288     0     ,
(                               0    7.52618
     0.245739   0.877237 (                    )}
  0.959473   0.281799
  - 0.281799 0.959473 svd(TP(Q)) ={ (                    )  (                )
     0.959473   0.281799     4.83288      0
    - 0.281799  0.959473  ,     0     7.52618  , (                    ) )
  0.0236042  0.419897  }
( - 0.969049 0.232684) )
   0.245739   0.877237

16.37.3.46 swap_columns, swap_rows
Syntax:

swap_columns(A,c1,c2);
A :-a matrix.
c1,c1 :- positive integers.
Synopsis:

swap_columns swaps column c1 of A with column c2.

swap_rows performs the same task on 2 rows of A.

Examples:

swap_columns(A,2,3) = ( 1  3  2)
( 4  6  5)

  7  9  8

Related functions:

swap_entries.

16.37.3.47 swap_entries
Syntax:

swap_entries(A,{r1,c1},{r2,c2});
A :-a matrix.
r1,c1,r2,c2 :- positive integers.
Synopsis:

swap_entries swaps A(r1,c1) with A(r2,c2).
Examples:

swap_entries(A,{1,1},{3,3}) = ( 9  2  3)
( 4  5  6)

  7  8  1

Related functions:

swap_columns, swap_rows.

16.37.3.48 swap_rows

See: swap_columns.

16.37.3.49 symmetricp
Syntax:

symmetricp(A);
A:-a matrix.
Synopsis:

symmetricp is a boolean function that returns t if the matrix is symmetric and nil otherwise.
Examples:
M = (     )
  1  2
  2  1
symmetricp(A) = nil
symmetricp(M) = t
Related functions:

matrixp, squarep.

16.37.3.50 toeplitz
Syntax:

toeplitz({expr1,expr2, …,exprn}); 21
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}) = ( w   x  y   z)
|             |
|( x   w  x   y|)
  y   x  w   x
  z   y  x  w

16.37.3.51 triang_adjoint
Syntax:

triang_adjoint(A);
A:-a matrix.
Synopsis:

triang_adjoint computes the triangularizing adjoint F of matrix A due to the algorithm of Arne Storjohann. F is lower triangular matrix and the resulting matrix T of F*A = T is upper triangular with the property that the i-th entry in the diagonal of T is the determinant of the principal i-th submatrix of the matrix A.

Examples:
triang_adjoint(A) = (           )
   1   0   0
( - 4  1   0)
  - 3  6  - 3
F*A = (           )
  1   2   3
( 0  - 3 - 6)
  0   0   0

16.37.3.52 Vandermonde
Syntax:

vandermonde({expr1,expr2, …,exprn}); 22
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}) = (            2 )
 1    x     x
(1  2 *y  4 *y2)
 1  3 *z  9 *z2

16.37.3.53 kronecker_product
Syntax:

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:

a1 := mat((1,2),(3,4),(5,6))$  
a2 := mat((1,1,1),(2,z,2),(3,3,3))$  
kronecker_product(a1,a2);

(                           )
  1    1    1   2    2    2
|| 2    z    2   4   2* z  4 ||
|| 3    3    3   6    6    6 ||
|| 3    3    3   4    4    4 ||
|| 6   3* z  6   8   4* z  8 ||
| 9    9    9   12   12   12|
|| 5    5    5   6    6    6 ||
|(                           |)
  10  5* z  10  12  6* z  12
  15   15   15  18   18   18

16.37.4 Fast Linear Algebra

By turning the fast_la switch on, the speed of the following functions will be increased:

add_columns add_rows augment_columnscolumn_dim
copy_into make_identitymatrix_augment matrix_stack
minor mult_column mult_row pivot
remove_columnsremove_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.

16.37.5 Acknowledgments

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.

Bibliography

[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)