LINALG: Linear algebra package
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 16.38 LINALG: Linear algebra package

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

Author: Matt Rebbeck.

#### 16.38.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.38.3 and are labelled 16.38.3.1 to 16.38.3.53. They can be classiﬁed into four sections(n.b: the numbers after the dots signify the function label in section 16.38.3).

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

##### 16.38.1.1 Basic matrix handling

add_columns | … | 16.38.3.1 | add_rows | … | 16.38.3.2
add_to_columns | … | 16.38.3.3 | add_to_rows | … | 16.38.3.4
augment_columns | … | 16.38.3.5 | char_poly | … | 16.38.3.9
column_dim | … | 16.38.3.12 | copy_into | … | 16.38.3.14
diagonal | … | 16.38.3.15 | extend | … | 16.38.3.16
ﬁnd_companion | … | 16.38.3.17 | get_columns | … | 16.38.3.18
get_rows | … | 16.38.3.19 | hermitian_tp | … | 16.38.3.21
matrix_augment | … | 16.38.3.28 | matrix_stack | … | 16.38.3.30
minor | … | 16.38.3.31 | mult_columns | … | 16.38.3.32
mult_rows | … | 16.38.3.33 | pivot | … | 16.38.3.34
remove_columns | … | 16.38.3.37 | remove_rows | … | 16.38.3.38
row_dim | … | 16.38.3.39 | rows_pivot | … | 16.38.3.40
stack_rows | … | 16.38.3.43 | sub_matrix | … | 16.38.3.44
swap_columns | … | 16.38.3.46 | swap_entries | … | 16.38.3.47
swap_rows | … | 16.38.3.48 |

##### 16.38.1.2 Constructors

Functions that create matrices.

band_matrix | … | 16.38.3.6 | block_matrix | … | 16.38.3.7
char_matrix | … | 16.38.3.8 | coeﬀ_matrix | … | 16.38.3.11
companion | … | 16.38.3.13 | hessian | … | 16.38.3.22
hilbert | … | 16.38.3.23 | mat_jacobian | … | 16.38.3.24
jordan_block | … | 16.38.3.25 | make_identity | … | 16.38.3.27
random_matrix | … | 16.38.3.36 | toeplitz | … | 16.38.3.50
Vandermonde | … | 16.38.3.52 | Kronecker_Product | … | 16.38.3.53

##### 16.38.1.3 High level algorithms

char_poly | … | 16.38.3.9 | cholesky | … | 16.38.3.10
gram_schmidt | … | 16.38.3.20 | lu_decom | … | 16.38.3.26
pseudo_inverse | … | 16.38.3.35 | simplex | … | 16.38.3.41
svd | … | 16.38.3.45 | triang_adjoint | … | 16.38.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.38.1.4 Predicates

matrixp | … | 16.38.3.29 | squarep | … | 16.38.3.42
symmetricp | … | 16.38.3.49 |

##### Note on examples:

In the examples the matrix 𝒜 will be

##### Notation

Throughout ℐ is used to indicate the identity matrix and 𝒜T to indicate the transpose of the matrix 𝒜.

#### 16.38.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 :=

##### 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.38.3 What’s available

##### 16.38.3.1 add_columns, add_rows

Syntax:
  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(𝒜,1,2,x) = |  |  |  |  |  |
  | add_rows(𝒜,2,3,5) = |  |  |  |  |  |

Related functions:
  add_to_columns, add_to_rows, mult_columns, mult_rows.

##### 16.38.3.2 add_rows

See: add_columns.

##### 16.38.3.3 add_to_columns, add_to_rows

Syntax:
  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 speciﬁed in column_list of 𝒜.

  add_to_rows performs the equivalent task on the rows of 𝒜.

Examples:

  | add_to_columns(𝒜,{1,2},10) = |  |  |  |  |  |
  | add_to_rows(𝒜,2,−x) = |  |  |  |  |  |

Related functions:
  add_columns, add_rows, mult_rows, mult_columns.

##### 16.38.3.4 add_to_rows

See: add_to_columns.

##### 16.38.3.5 augment_columns, stack_rows

Syntax:
  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 𝒜 speciﬁed in column_list and sticks them together.
  stack_rows performs the same task on rows of 𝒜.
Examples:

  | augment_columns(𝒜,{1,2}) = |  |  |  |  |  |
  | stack_rows(𝒜,{1,3}) = |  |  |  |  |  |

Related functions:
  get_columns, get_rows, sub_matrix.

##### 16.38.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 ﬁll 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.

##### 16.38.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 ﬁlled from the matrix_list row-wise.
Examples:

  | ℬ = ,𝒞 = ,𝒟 = |  |  |  |  |  |
  | block_matrix(2,3,{ℬ,𝒞,𝒟,𝒟,𝒞,ℬ}) = |  |  |  |  |  |

##### 16.38.3.8 char_matrix

Syntax:
  char_matrix(𝒜,λ);

  𝒜 | :- | a square matrix.
  λ | :- | a symbol or algebraic expression.

Synopsis:
  char_matrix creates the characteristic matrix 𝒞 of 𝒜. This is 𝒞 = λℐ−𝒜.
Examples:

  char_matrix(𝒜,x) =

Related functions:
  char_poly.

##### 16.38.3.9 char_poly

Syntax:
  char_poly(𝒜,λ);

  𝒜 | :- | a square matrix.
  λ | :- | a symbol or algebraic expression.

Synopsis:
  char_poly ﬁnds the characteristic polynomial of 𝒜.

  This is the determinant of λℐ−𝒜.

Examples:
  char_poly(𝒜,x) = x3 − 15 ∗ x2 − 18 ∗ x
Related functions:
  char_matrix.

##### 16.38.3.10 cholesky

Syntax:
  cholesky(𝒜);

  𝒜 | :- | a positive deﬁnite 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.

##### 16.38.3.11 coeﬀ_matrix

Syntax:
  coeff_matrix({lin_eqn1,lin_eqn2, …,lin_eqnn}); 30

  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 coeﬃcient matrix 𝒞 of the linear equations. It returns {𝒞,𝒳,ℬ} such that 𝒞𝒳 = ℬ.
Examples:

  | coeff_matrix({x + y + 4 ∗ z = 10,y + x − z = 20,x + y + 4}) = |  |  |  |  |  |

##### 16.38.3.12 column_dim, row_dim

Syntax:
  column_dim(𝒜);

  𝒜 | :- | a matrix.

Synopsis:
  column_dim ﬁnds the column dimension of 𝒜.
  row_dim ﬁnds the row dimension of 𝒜.
Examples:
  column_dim(𝒜) = 3

##### 16.38.3.13 companion

Syntax:
  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.

##### 16.38.3.14 copy_into

Syntax:
  copy_into(𝒜,ℬ,r,c);

  𝒜,ℬ | :- | matrices.
  r,c | :- | positive integers.

Synopsis:
  copy_into copies matrix 𝒜 into ℬ with 𝒜(1,1) at ℬ(r,c).
Examples:

  | 𝒢 = |  |  |  |  |  |
  | copy_into(𝒜,𝒢,1,2) = |  |  |  |  |  |

Related functions:
  augment_columns, extend, matrix_augment, matrix_stack, stack_rows, sub_matrix.

##### 16.38.3.15 diagonal

Syntax:
  diagonal({mat1,mat2, …,matn});31

  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({𝒜,x,ℋ}) = |  |  |  |  |  |

Related functions:
  jordan_block.

##### 16.38.3.16 extend

Syntax:
  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(𝒜,1,2,x) =

Related functions:
  copy_into, matrix_augment, matrix_stack, remove_columns, remove_rows.

##### 16.38.3.17 ﬁnd_companion

Syntax:
  find_companion(𝒜,x);

  𝒜 | :- | a matrix.
  x | :- | the variable.

Synopsis:
  Given a companion matrix, find_companion ﬁnds the polynomial from which it was made.
Examples:

  | 𝒞 = |  |  |  |  |  |
  | find_companion(𝒞,x) = x4 + 17 ∗ x3 − 9 ∗ x2 + 11 |  |  |  |  |  |

Related functions:
  companion.

##### 16.38.3.18 get_columns, get_rows

Syntax:
  get_columns(𝒜,column_list);

  𝒜 | :- | a matrix.
  c | :- | either a positive integer or a list of positive integers.

Synopsis:
  get_columns removes the columns of 𝒜 speciﬁed 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(𝒜,{1,3}) = |  |  |  |  |  |
  | get_rows(𝒜,2) = |  |  |  |  |  |

Related functions:
  augment_columns, stack_rows, sub_matrix.

##### 16.38.3.19 get_rows

See: get_columns.

##### 16.38.3.20 gram_schmidt

Syntax:
  gram_schmidt({vec1,vec2, …,vecn}); 32

  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}}) = {{,},{,}}

##### 16.38.3.21 hermitian_tp

Syntax:
  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:
  tp33 .

##### 16.38.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}) =

Related functions:
  df34 .

##### 16.38.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) =

##### 16.38.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}) = |  |  |  |  |  |

Related functions:
  hessian, df35 .

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

##### 16.38.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 𝒥 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.

##### 16.38.3.26 lu_decom

Syntax:
  lu_decom(𝒜);

  𝒜 | :- | a matrix containing either numeric entries or imaginary entries with numeric coeﬃcients.

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(𝒦,third lu) | = |  |  |  |  |  |

  𝒫 =

  lu := lu_decom(𝒫) = |  |  |

  first lu * second lu | = |  |  |  |  |  |
  convert(𝒫,thirdlu) | = |  |  |  |  |  |

Related functions:
  cholesky.

##### 16.38.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) =

Related functions:
  diagonal.

##### 16.38.3.28 matrix_augment, matrix_stack

Syntax:
  matrix_augment({mat1,mat2, …,matn});36

  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.

##### 16.38.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(𝒜) = t

  matrixp(doodlesackbanana) = nil

Related functions:
  squarep, symmetricp.

##### 16.38.3.30 matrix_stack

See: matrix_augment.

##### 16.38.3.31 minor

Syntax:
  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(𝒜,1,3) =

Related functions:
  remove_columns, remove_rows.

##### 16.38.3.32 mult_columns, mult_rows

Syntax:
  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 speciﬁed in column_list have been multiplied by expr.

  mult_rows performs the same task on the rows of 𝒜.

Examples:

  | mult_columns(𝒜,{1,3},x) = |  |  |  |  |  |
  | mult_rows(𝒜,2,10) = |  |  |  |  |  |

Related functions:
  add_to_columns, add_to_rows.

##### 16.38.3.33 mult_rows

See: mult_columns.

##### 16.38.3.34 pivot

Syntax:
  pivot(𝒜,r,c);

  𝒜 | :- | a matrix.
  r,c | :- | positive integers such that 𝒜(r,c)≠0.

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(𝒜,2,3) =

Related functions:
  rows_pivot.

##### 16.38.3.35 pseudo_inverse

Syntax:
  pseudo_inverse(𝒜);

  𝒜 | :- | a matrix containing only real numeric entries.

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 𝒜† is deﬁned by 𝒜† = 𝒱Σ†𝒰T . For the diagonal matrix Σ, the pseudoinverse Σ† is computed by taking the reciprocal of only the nonzero diagonal elements.

  If 𝒜 is square and non-singular, then 𝒜† = 𝒜. In general, however, 𝒜𝒜†𝒜 = 𝒜, and 𝒜†𝒜𝒜† = 𝒜†.

  Perhaps more importantly, 𝒜† solves the following least-squares problem: given a rectangular matrix 𝒜 and a vector b, ﬁnd the x minimizing ∥𝒜x − b∥2, and which, in addition, has minimum ℓ2 (euclidean) Norm, ∥x∥2. This x is 𝒜†b.

Examples:

Related functions:
  svd.

##### 16.38.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) = |  |  |  |  |  |
  on only_integer, not_negative, upper_matrix, imaginary;
  | random_matrix(4,4,10) = |  |  |  |  |  |

##### 16.38.3.37 remove_columns, remove_rows

Syntax:
  remove_columns(𝒜,column_list);

  𝒜 | :- | a matrix.
  column_list | :- | either a positive integer or a list of positive integers.

Synopsis:
  remove_columns removes the columns speciﬁed in column_list from 𝒜.

  remove_rows performs the same task on the rows of 𝒜.

Examples:

  remove_columns(𝒜,2) | = |  |  |  |  |  |
  remove_rows(𝒜,{1,3}) | = |  |  |  |  |  |

Related functions:
  minor.

##### 16.38.3.38 remove_rows

See: remove_columns.

##### 16.38.3.39 row_dim

See: column_dim.

##### 16.38.3.40 rows_pivot

Syntax:
  rows_pivot(𝒜,r,c,{row_list});

  𝒜 | :- | a matrix.
  r,c | :- | positive integers such that 𝒜(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 speciﬁed in row_list.
Examples:

  | 𝒩 = |  |  |  |  |  |  |  |
  | rows_pivot(𝒩,2,3,{4,5}) | = |  |  |  |  |  |  |  |  |

Related functions:
  pivot.

##### 16.38.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 speciﬁed for the LP ﬁle 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 ﬁnd 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.38.3.42 squarep

Syntax:
  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.

##### 16.38.3.43 stack_rows

See: augment_columns.

##### 16.38.3.44 sub_matrix

Syntax:
  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 speciﬁed in row_list and the columns speciﬁed in column_list.
Examples:

  sub_matrix(𝒜,{1,3},{2,3}) =

Related functions:
  augment_columns, stack_rows.

##### 16.38.3.45 svd (singular value decomposition)

Syntax:
  svd(𝒜);

  𝒜 | :- | a matrix containing only real numeric entries.

Synopsis:
  svd computes the singular value decomposition of 𝒜. If A is an m × n real matrix of (column) rank r, svd returns the 3-element list {𝒰,Σ,𝒱} where 𝒜 = 𝒰Σ𝒱T .

  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 𝒜; only r of these are non-zero. The singular values are the non-negative square roots of the eigenvalues of 𝒜T 𝒜.

  𝒰 and 𝒱 are such that 𝒰𝒰T = 𝒱𝒱T = 𝒱T 𝒱 = ℐk.

  Note: there are a number of diﬀerent deﬁnitions 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:

  | 𝒬 = |  |  |  |  |  |
  | svd(𝒬) = svd(TP(𝒬)) = |  |  |  |

##### 16.38.3.46 swap_columns, swap_rows

Syntax:
  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(𝒜,2,3) =

Related functions:
  swap_entries.

##### 16.38.3.47 swap_entries

Syntax:
  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(𝒜,{1,1},{3,3}) =

Related functions:
  swap_columns, swap_rows.

##### 16.38.3.48 swap_rows

See: swap_columns.

##### 16.38.3.49 symmetricp

Syntax:
  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.

##### 16.38.3.50 toeplitz

Syntax:
  toeplitz({expr1,expr2, …,exprn}); 37

  expr1,expr2, …,exprn | :- | algebraic expressions.

Synopsis:
  toeplitz creates the toeplitz matrix from the expression list.

  This is a square symmetric matrix in which the ﬁrst 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}) =

##### 16.38.3.51 triang_adjoint

Syntax:
  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(𝒜) = |  |  |  |  |  |
  | ℱ∗𝒜 = |  |  |  |  |  |

##### 16.38.3.52 Vandermonde

Syntax:
  vandermonde({expr1,expr2, …,exprn}); 38

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

##### 16.38.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);

#### 16.38.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_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 insigniﬁcant unless you are making a signiﬁcant 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.38.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.

Up | Next | Prev | PrevTail | Front