REDUCE

16.36 LINALG: Linear algebra package

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

Author: Matt Rebbeck.

16.36.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.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).

16.36.1.1 Basic matrix handling

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_columns16.36.3.5 char_poly 16.36.3.9
column_dim 16.36.3.12copy_into 16.36.3.14
diagonal 16.36.3.15extend ldots16.36.3.16
find_companion 16.36.3.17get_columns 16.36.3.18
get_rows 16.36.3.19hermitian_tp 16.36.3.21
matrix_augment 16.36.3.28matrix_stack 16.36.3.30
minor 16.36.3.31mult_columns16.36.3.32
mult_rows 16.36.3.33pivot 16.36.3.34
remove_columns 16.36.3.37remove_rows 16.36.3.38
row_dim 16.36.3.39rows_pivot 16.36.3.40
stack_rows 16.36.3.43sub_matrix 16.36.3.44
swap_columns 16.36.3.46swap_entries 16.36.3.47
swap_rows 16.36.3.48

16.36.1.2 Constructors

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.13hessian 16.36.3.22
hilbert 16.36.3.23mat_jacobian 16.36.3.24
jordan_block 16.36.3.25make_identity 16.36.3.27
random_matrix16.36.3.36toeplitz 16.36.3.50
Vandermonde 16.36.3.52Kronecker_Product16.36.3.53

16.36.1.3 High level algorithms

char_poly 16.36.3.9 cholesky 16.36.3.10
gram_schmidt 16.36.3.20lu_decom 16.36.3.26
pseudo_inverse16.36.3.35simplex 16.36.3.41
svd 16.36.3.45triang_adjoint16.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.

16.36.1.4 Predicates

matrixp 16.36.3.29squarep16.36.3.42
symmetricp16.36.3.49

Note on examples:

In the examples the matrix A will be

A = (         )
  1  2  3
( 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.36.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.36.3 What’s available

16.36.3.1 add_columns, add_rows

  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.36.3.2 add_rows

  see: add_columns.

16.36.3.3 add_to_columns, add_to_rows

  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.36.3.4 add_to_rows

  see: add_to_columns.

16.36.3.5 augment_columns, stack_rows

  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})
=
(       )
   1  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.36.3.6 band_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)
=
(                   )
  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.36.3.7 block_matrix

  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.36.3.8 char_matrix

  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 = λIA.

Examples:

char_matrix(A,x)
=
(                     )
   x− 1   − 2    − 3
(   − 4  x − 5   − 6  )
    − 7   − 8   x − 9

Related functions:

  char_poly.

16.36.3.9 char_poly

  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 λIA.

Examples:

  char_poly(A,x) = x3 15 x2 18 x

Related functions:

  char_matrix.

16.36.3.10 cholesky

  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  √2-  0  ) ,|(  0   2   1√--|)
|(    0  √1- √1-               1√2-  |)
         2    2       0   0    2

Related functions:

  lu_decom.

16.36.3.11 coeff_matrix

  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 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.36.3.12 column_dim, row_dim

  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.36.3.13 companion

  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,i1) for i = 1,,n, C(i,i1) = 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.36.3.14 copy_into

  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.36.3.15 diagonal

  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:

  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.36.3.16 extend

  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.36.3.17 find_companion

  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.36.3.18 get_columns, get_rows

  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.36.3.19 get_rows

  see: get_columns.

16.36.3.20 gram_schmidt

  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}}) = {{√1-
 5,2√--
 5},{2∗√5
  5,−-√5
  5}}

16.36.3.21 hermitian_tp

  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:

  tp15 .

16.36.3.22 hessian

  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:

  df16 .

16.36.3.23 hilbert

  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−-2  x+y−3- x+y−4-
|(  x+−y1−-3  x−+y1−4- x+−y1−5-|)
   --−1--  -−-1-- --−1--
   x+y− 4  x+y−5  x+y−6

16.36.3.24 jacobian

  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      )
          3       3             2
   0  y ∗ z   x ∗z    3 ∗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.

16.36.3.25 jordan_block

  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.36.3.26 lu_decom

  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

                      ( (                                       )
                      {      1       0               0
lu := lu_decom (P)  =    (    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,third lu)
=
(    1     i     0   )
(                    )
     4     5     2
   i+ 1  i + 2  i+ 3

Related functions:

  cholesky.

16.36.3.27 make_identity

  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.36.3.28 matrix_augment, matrix_stack

  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({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.36.3.29 matrixp

  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.36.3.30 matrix_stack

  see: matrix_augment.

16.36.3.31 minor

  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.36.3.32 mult_columns, mult_rows

  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.36.3.33 mult_rows

  see: mult_columns.

16.36.3.34 pivot

  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.36.3.35 pseudo_inverse

  pseudo_inverse(A);

A:-a matrix.

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 A1 is defined by A1 = VT 1U.

Thus Apseudo_inverse(A) = I.

Examples:

pseudo_inverse(A)
=
(                )
    − 0.2   0.1
||  − 0.05   0.05  ||
(   0.1     0    )
    0.25   − 0.05

Related functions:

  svd.

16.36.3.36 random_matrix

  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.36.3.37 remove_columns, remove_rows

  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.36.3.38 remove_rows

  see: remove_columns.

16.36.3.39 row_dim

  see: column_dim.

16.36.3.40 rows_pivot

  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.36.3.41 simplex

  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.36.3.42 squarep

  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.36.3.43 stack_rows

  see: augment_columns.

16.36.3.44 sub_matrix

  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.36.3.45 svd (singular value decomposition)

  svd(A);

A:-a matrix containing only numeric entries.

Synopsis:

svd computes the singular value decomposition of A.

It returns {U, ,V} where A = U VT and = diag(σ1,n).σi for i = (1n) are the singular values of A.

n is the column dimension of A.

The singular values of A are the non-negative square roots of the eigenvalues of AT A.

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

Examples:

  Q = (  1   3 )

  − 4  3

            {(                      )  (                    )
                 0.289784   0.957092      5.149162      0
svd(Q ) =       − 0.957092  0.289784   ,      0     2.913094   ,
            (                        )}
               − 0.687215   0.726453
               − 0.726453  − 0.687215

16.36.3.46 swap_columns, swap_rows

  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.36.3.47 swap_entries

  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.36.3.48 swap_rows

  see: swap_columns.

16.36.3.49 symmetricp

  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.36.3.50 toeplitz

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

   z  y   x  w
16.36.3.51 triang_adjoint

  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 FA = 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

FA
=
(             )
   1   2   3
(  0  − 3 − 6 )
   0   0   0

16.36.3.52 Vandermonde

  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(j1). 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.36.3.53 kronecker_product

  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.36.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.36.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)