Skip to content

Matrices

CalcpadCE treats matrices as first-class values: a two-dimensional grid of numbers that flows through the same arithmetic, comparison and function calls as scalars and vectors, with row–column rules that keep formulas readable on the worksheet.

The six worksheets in this group walk through the full matrix toolkit step by step. The journey starts with literal construction with | row separators and the indexing/slicing notation, then covers the creational helpers (\(matrix\), \(identity\), \(diagonal\), random, banded) used to assemble structured matrices. Data functions handle row- and column-wise sorting, ordering, lookup and reductions; math functions provide the linear-algebra primitives — Hadamard product, determinant, inverse, transpose, norms and decomposition helpers — and structural functions expose row/column counts, resizing, joining, reshaping and submatrix extraction. The tour closes with matrix and matrix–vector operators, the element-wise versus algebraic multiplication rules, and the comparison and logical operations that broadcast across whole grids.

Matrix Initialization and Indexing

Foundations of matrices in CalcpadCE: literal construction with \(|\) row separators, single- and double-index access, slicing, submatrix extraction and assignment by index.

Code:
'Direct:
A = [1|2; 3|4; 5; 6|7; 8]
'Direct with vectors:
a = [1; 2; 4]
A = [a|2*a + 1|3*a + 2]
'From a custom function (with vector arguments):
A(x) = transp([x^0|x|x^2|x^3|x^4])
x = [1; 2; 3; 4]
A = A(x)

"Indexing
'<hr/>
A.(3; 2)'- simple dot operator (constant index)
i = 2', 'j = 3
A.(2*i - 1; j + 1)'- expressions with variables
A.(i; j) = 0' - assign a new value to an element:'A
'Initalize values in a block loop
x = [1; 2; 3; 4]
A = matrix(len(x); 7)
#hide
#for i = 1 : n_rows(A)
    #for j = 1 : n_cols(A)
        A.(i; j) = x.i^(j - 1)
    #loop
#loop
#show
A
'Inline loop
B = matrix(len(x); 7)
$Repeat{$Repeat{B.(i; j) = x.i^(j - 1) @ j = 1 : n_cols(B)} @ i = 1 : n_rows(B)}
B
Rendered Output:

Direct:

A = [1 | 2; 3 | 4; 5; 6 | 7; 8] = 100 230 456 780

Direct with vectors:

a = [1; 2; 4] = [1 2 4]

A = [a | 2 · a + 1 | 3 · a + 2] = 124 359 5814

From a custom function (with vector arguments):

A ( x )  = transp ( [x0 | x | x2 | x3 | x4] ) 

x = [1; 2; 3; 4] = [1 2 3 4]

A = A  ( x )  = 11111 124816 1392781 141664256

 

Indexing

A3,2 = 3 - simple dot operator (constant index)

i = 2 , j = 3

A3,4 = 27 - expressions with variables

A2,3 = 0 - assign a new value to an element: A = 11111 120816 1392781 141664256

Initalize values in a block loop

x = [1; 2; 3; 4] = [1 2 3 4]

A = matrix ( len ( x ) ; 7 )  = 0000000 0000000 0000000 0000000

A = 1111111 1248163264 1392781243729 14166425610244096

Inline loop

B = matrix ( len ( x ) ; 7 )  = 0000000 0000000 0000000 0000000

$Repeat{$Repeat{Bi,j = xij − 1 for j = 1...ncols ( B ) } for i = 1...nrows ( B ) } = 4096

B = 1111111 1248163264 1392781243729 14166425610244096

Matrix Creational Functions

Creational helpers for matrices: \(matrix\), \(identity\), \(diagonal\), \(utriang\), \(ltriang\), \(symmetric\), banded, random and Vandermonde constructors.

Code:
'<style>em {font-family:"Times New Roman";}</style>
'<p><b>Matrix</b>(<em>m</em>; <em>n</em>)</p><hr/>
matrix(3; 4)'- creates a 3x4 full (rectangular) matrix

'<p><b>Identity</b>(<em>n</em>)</p><hr/>
identity(3)'- creates  a 3x3 identity matrix (diagonal filled with ones)

'<p><b>Diagonal</b>(<em>n</em>, <em>value</em>)</p><hr/>
diagonal(3; 2)'- creates a 3x3 diagonal matrix filled with 2

'<p><b>Column</b>(<em>m</em>, <em>value</em>)</p><hr/>
column(3; 2)'- creates a 3x1 column matrix filled with 2

'<p><b>Utriang</b>(<em>n</em>, <em>value</em>)</p><hr/>
U = utriang(3)'- creates a 3x3 upper triangular matrix
mfill(U; 1)'- fills the matrix with value of 1

'<p><b>Ltriang</b>(<em>n</em>, <em>value</em>)</p><hr/>
L = ltriang(3)'- creates a 3x3 lower triangular matrix
mfill(L; 1)'- fills the matrix with value of 1

'<p><b>Symmetric</b>(<em>n</em>)</p><hr/>
A = symmetric(4)'- creates a 4x4 empty symmetrix matrix
A.(1; 1) = 5', 'A.(1; 2) = 4'- assign some values
A.(2; 2) = 3', 'A.(2; 3) = 2
A.(4; 2) = 1', 'A.(4; 4) = 1
A'- symmetric values has also changed to preserve symmetry

'<p><b>Vec2diag</b>(<em>vector</em>)</p><hr/>
vec2diag([1; 2; 3])'- creates a 3x3 diagonal matrix from a vector

'<p><b>Vec2col</b>(<em>vector</em>)</p><hr/>
vec2col([1; 2; 3])'- creates a 3x3 column matrix from a vector

'<p><b>Join_Cols</b>(<em>list of vectors</em>)</p><hr/>
join_cols([1]; [4; 5; 6]; [7; 8]; [10; 11; 12])'- creates a general rectangular matrix by joining the input vectors into columns

'<p><b>Join_Rows</b>(<em>list of vectors</em>)</p><hr/>
join_rows([1; 2; 3; 4]; [6; 7; 8; 9; 10])'- creates a general rectangular matrix by joining the input vectors into rows

'<p><b>Augment</b>(<em>list of matrices</em>)</p><hr/>
A = [1; 2|3; 4]
B = [1; 2; 3|4; 5; 6|7; 8; 9]
c = [10; 11; 12; 13]
D = augment(A; B; c)'- creates a general rectangular matrix by joining the input matrices side to side

'<p><b>Stack</b>(<em>list of matrices</em>)</p><hr/>
A = [1; 2|3; 4]
B = [1; 2; 3|4; 5; 6|7; 8; 9]
c = [10; 11]
D = stack(A; B; c)'- creates a general rectangular matrix by joining the input matrices one below the other
Rendered Output:

Matrix(m; n)


matrix ( 3; 4 )  = 0000 0000 0000 - creates a 3x4 full (rectangular) matrix

 

Identity(n)


identity ( 3 )  = 100 010 001 - creates a 3x3 identity matrix (diagonal filled with ones)

 

Diagonal(n, value)


diagonal ( 3; 2 )  = 200 020 002 - creates a 3x3 diagonal matrix filled with 2

 

Column(m, value)


column ( 3; 2 )  = 2 2 2 - creates a 3x1 column matrix filled with 2

 

Utriang(n, value)


U = utriang ( 3 )  = 000 000 000 - creates a 3x3 upper triangular matrix

mfill ( U; 1 )  = 111 011 001 - fills the matrix with value of 1

 

Ltriang(n, value)


L = ltriang ( 3 )  = 000 000 000 - creates a 3x3 lower triangular matrix

mfill ( L; 1 )  = 100 110 111 - fills the matrix with value of 1

 

Symmetric(n)


A = symmetric ( 4 )  = 0000 0000 0000 0000 - creates a 4x4 empty symmetrix matrix

A1,1 = 5 , A1,2 = 4 - assign some values

A2,2 = 3 , A2,3 = 2

A4,2 = 1 , A4,4 = 1

A = 5400 4321 0200 0101 - symmetric values has also changed to preserve symmetry

 

Vec2diag(vector)


vec2diag ( [1; 2; 3] )  = 100 020 003 - creates a 3x3 diagonal matrix from a vector

 

Vec2col(vector)


vec2col ( [1; 2; 3] )  = 1 2 3 - creates a 3x3 column matrix from a vector

 

Join_Cols(list of vectors)


joincols ( [1]; [4; 5; 6]; [7; 8]; [10; 11; 12] )  = 14710 05811 06012 - creates a general rectangular matrix by joining the input vectors into columns

 

Join_Rows(list of vectors)


joinrows ( [1; 2; 3; 4]; [6; 7; 8; 9; 10] )  = 12340 678910 - creates a general rectangular matrix by joining the input vectors into rows

 

Augment(list of matrices)


A = [1; 2 | 3; 4] = 12 34

B = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

c = [10; 11; 12; 13] = [10 11 12 13]

D = augment ( A; B; c )  = 1212310 3445611 0078912 0000013 - creates a general rectangular matrix by joining the input matrices side to side

 

Stack(list of matrices)


A = [1; 2 | 3; 4] = 12 34

B = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

c = [10; 11] = [10 11]

D = stack ( A; B; c )  = 120 340 123 456 789 1000 1100 - creates a general rectangular matrix by joining the input matrices one below the other

Matrix Data Functions

Data-oriented matrix toolkit: row- and column-wise sorting, ordering, search, plus the standard reductions (\(sum\), \(product\), \(min\), \(max\), \(mean\)).

Code:
'<style>em {font-family:"Times New Roman";}</style>
'<p><b>Sort_Cols</b>(<em>matrix</em>; <em>row index</em>) and <b>Rsort_Cols</b>(<em>matrix</em>; <em>row index</em>)</p><hr/>
A = [5; 2; 3|4; 9; 1|6; 8; 7]
B = sort_cols(A; 2)'- the matrix sorted by row 2 in ascending order
C = rsort_cols(A; 2)'- the matrix sorted by row 2 in descending order
A' - the original matrix remains unchanged

'<p><b>Sort_Rows</b>(<em>matrix</em>; <em>column index</em>) and <b>Rsort_Rows</b>(<em>matrix</em>; <em>column index</em>)</p><hr/>
A = [5; 2; 3|4; 9; 1|6; 8; 7]
B = sort_rows(A; 2)'- the matrix sorted by column 2 in ascending order
C = rsort_rows(A; 2)'- the matrix sorted by column 2 in descending order
A' - the original matrix remains unchanged

'<p><b>Order_Cols</b>(<em>matrix</em>; <em>row index</em>) and <b>Revorder_Cols</b>(<em>matrix</em>; <em>row index</em>)</p><hr/>
A = [5; 2; 3|4; 9; 1|6; 8; 7]
b = order_cols(A; 2)'- the indexes of matrix columns ordered by the values in row 2 in ascending order
B = extract_cols(A; b)'- the matrix sorted by row 2 in ascending order
c = revorder_cols(A; 2)'- the indexes of matrix columns ordered by the values in row 2 in descending order
C = extract_cols(A; c)'- the matrix sorted by row 2 in descending order

'<p><b>Order_Rows</b>(<em>matrix</em>; <em>column index</em>) and <b>Revorder_Rows</b>(<em>matrix</em>; <em>column index</em>)</p><hr/>
A = [5; 2; 3|4; 9; 1|6; 8; 7]
b = order_rows(A; 2)'- the indexes of matrix rows ordered by the values in column 2 in ascending order
B = extract_rows(A; b)
c = revorder_rows(A; 2)'- the matrix sorted by row 2 in descending order
C = extract_rows(A; c)'- the indexes of matrix rows ordered by the values in column 2 in descending order

'<p><b>Mcount</b>(<em>matrix</em>; <em>value</em>)</p><hr/>
A = [1; 0; 1|2; 1; 2|1; 3; 1]
n = mcount(A; 1)'- the number of occurances of value 1 in matrix A

'<p><b>Msearch</b>(<em>matrix</em>; <em>value</em>; <em>starting row index</em>; <em>starting column index</em>)</p><hr/>
A = [1; 2; 3|1; 5; 6|1; 8; 9]
b = msearch(A; 1; 1; 1)' - the row and column indexes of the first occurance of value 1 in A, starting from (1,1)
c = msearch(A; 1; 2; 2)' - the same are previous, but starting  from (2,2)
d = msearch(A; 4; 1; 1)' - if the value is not found [0 0] is returned

'<p><b>Mfind</b>(<em>matrix</em>; <em>value</em>)</p><hr/>
A = [1; 2; 3|4; 1; 6|1; 8; 9]
B = mfind(A; 1)' - the row and column indexes of all elements in A, that are equal to 1
C = mfind_ne(A; 1)' - the row and column indexes of all elements in A, that are not equal to 1
D = mfind_lt(A; 5)' - the row and column indexes of all elements in A, that are less than 5
E = mfind(A; 5)'- if the value is not found

'<p><b>Hlookup</b>(<em>matrix</em>; <em>value</em>; <em>reference row</em>; <em>return row</em>)</p><hr/>
A = [0; 1; 0; 1|1; 2; 3; 4; 5|6; 7; 8; 9; 10]
b = hlookup(A; 0; 1; 3)'- the values in row 3, where row 1 contains zeros
c = hlookup_ne(A; 0; 1; 3)'- the values in row 3, where row 1  does not contain zeros
d = hlookup_lt(A; 9; 3; 2)'- the values in row 2, where the respective values in row 3 are &lt; 9
e = hlookup_ge(A; 8; 3; 2)'- the values in row 2, where the respective values in row 3 are &ge; 8
f = hlookup(A; 0; 1; 3)'- the values in row 3, where row 1 contains zeros
g = hlookup(A; 2; 1; 3)'- since 2 is not found in row 1, an empty vector is returned

'<p><b>Vlookup</b>(<em>matrix</em>; <em>value</em>; <em>reference column</em>; <em>return column</em>)</p><hr/>
A = [1; 2|3; 4; 1|5; 6|7; 8; 1|9; 10]
b = vlookup(A; 0; 3; 1)'- the values in column 1, where column 3 contains zeros
c = vlookup_ne(A; 0; 3; 2)'- the values in column 2, where column 3 does not contain zeros
d = vlookup_le(A; 5; 1; 2)'- the values in column 2, where the respective values in column 1 are &le; 5
e = vlookup_gt(A; 3; 1; 2)'- the values in column 2, where the respective values in column 1 are &gt; 3
f = vlookup(A; 2; 3; 1)'- since 2 is not found in column 3, an empty vector is returned
Rendered Output:

Sort_Cols(matrix; row index) and Rsort_Cols(matrix; row index)


A = [5; 2; 3 | 4; 9; 1 | 6; 8; 7] = 523 491 687

B = sortcols ( A; 2 )  = 352 149 768 - the matrix sorted by row 2 in ascending order

C = rsortcols ( A; 2 )  = 253 941 867 - the matrix sorted by row 2 in descending order

A = 523 491 687 - the original matrix remains unchanged

 

Sort_Rows(matrix; column index) and Rsort_Rows(matrix; column index)


A = [5; 2; 3 | 4; 9; 1 | 6; 8; 7] = 523 491 687

B = sortrows ( A; 2 )  = 523 687 491 - the matrix sorted by column 2 in ascending order

C = rsortrows ( A; 2 )  = 491 687 523 - the matrix sorted by column 2 in descending order

A = 523 491 687 - the original matrix remains unchanged

 

Order_Cols(matrix; row index) and Revorder_Cols(matrix; row index)


A = [5; 2; 3 | 4; 9; 1 | 6; 8; 7] = 523 491 687

b = ordercols ( A; 2 )  = [3 1 2] - the indexes of matrix columns ordered by the values in row 2 in ascending order

B = extractcols ( A; b )  = 352 149 768 - the matrix sorted by row 2 in ascending order

c = revordercols ( A; 2 )  = [2 1 3] - the indexes of matrix columns ordered by the values in row 2 in descending order

C = extractcols ( A; c )  = 253 941 867 - the matrix sorted by row 2 in descending order

 

Order_Rows(matrix; column index) and Revorder_Rows(matrix; column index)


A = [5; 2; 3 | 4; 9; 1 | 6; 8; 7] = 523 491 687

b = orderrows ( A; 2 )  = [1 3 2] - the indexes of matrix rows ordered by the values in column 2 in ascending order

B = extractrows ( A; b )  = 523 687 491

c = revorderrows ( A; 2 )  = [2 3 1] - the matrix sorted by row 2 in descending order

C = extractrows ( A; c )  = 491 687 523 - the indexes of matrix rows ordered by the values in column 2 in descending order

 

Mcount(matrix; value)


A = [1; 0; 1 | 2; 1; 2 | 1; 3; 1] = 101 212 131

n = mcount ( A; 1 )  = 5 - the number of occurances of value 1 in matrix A

 

Msearch(matrix; value; starting row index; starting column index)


A = [1; 2; 3 | 1; 5; 6 | 1; 8; 9] = 123 156 189

b = msearch ( A; 1; 1; 1 )  = [1 1] - the row and column indexes of the first occurance of value 1 in A, starting from (1,1)

c = msearch ( A; 1; 2; 2 )  = [3 1] - the same are previous, but starting from (2,2)

d = msearch ( A; 4; 1; 1 )  = [0 0] - if the value is not found [0 0] is returned

 

Mfind(matrix; value)


A = [1; 2; 3 | 4; 1; 6 | 1; 8; 9] = 123 416 189

B = mfind ( A; 1 )  = 123 121 - the row and column indexes of all elements in A, that are equal to 1

C = mfindne ( A; 1 )  = 112233 231323 - the row and column indexes of all elements in A, that are not equal to 1

D = mfindlt ( A; 5 )  = 111223 123121 - the row and column indexes of all elements in A, that are less than 5

E = mfind ( A; 5 )  = 0 0 - if the value is not found

 

Hlookup(matrix; value; reference row; return row)


A = [0; 1; 0; 1 | 1; 2; 3; 4; 5 | 6; 7; 8; 9; 10] = 01010 12345 678910

b = hlookup ( A; 0; 1; 3 )  = [6 8 10] - the values in row 3, where row 1 contains zeros

c = hlookupne ( A; 0; 1; 3 )  = [7 9] - the values in row 3, where row 1 does not contain zeros

d = hlookuplt ( A; 9; 3; 2 )  = [1 2 3] - the values in row 2, where the respective values in row 3 are < 9

e = hlookupge ( A; 8; 3; 2 )  = [3 4 5] - the values in row 2, where the respective values in row 3 are ≥ 8

f = hlookup ( A; 0; 1; 3 )  = [6 8 10] - the values in row 3, where row 1 contains zeros

g = hlookup ( A; 2; 1; 3 )  = [] - since 2 is not found in row 1, an empty vector is returned

 

Vlookup(matrix; value; reference column; return column)


A = [1; 2 | 3; 4; 1 | 5; 6 | 7; 8; 1 | 9; 10] = 120 341 560 781 9100

b = vlookup ( A; 0; 3; 1 )  = [1 5 9] - the values in column 1, where column 3 contains zeros

c = vlookupne ( A; 0; 3; 2 )  = [4 8] - the values in column 2, where column 3 does not contain zeros

d = vlookuple ( A; 5; 1; 2 )  = [2 4 6] - the values in column 2, where the respective values in column 1 are ≤ 5

e = vlookupgt ( A; 3; 1; 2 )  = [6 8 10] - the values in column 2, where the respective values in column 1 are > 3

f = vlookup ( A; 2; 3; 1 )  = [] - since 2 is not found in column 3, an empty vector is returned

Matrix Math Functions

Linear-algebra primitives: Hadamard product, determinant, inverse, transpose, trace, rank, \(L_p\) and Frobenius norms, plus solver and decomposition helpers.

Code:
'<style>em {font-family:"Times New Roman";}</style>
'<p><b>Hprod</b>(<em>first matrix</em>; <em>second matrix</em>)</p><hr/>
A = [1; 2|3; 4|5; 6]'- first matrix
B = [9; 8|7; 6|5; 4]'- second matrix
C = hprod(A; B)'- The Hadamard product of matrices A and B

'<p><b>Fprod</b>(<em>first matrix</em>; <em>second matrix</em>)</p><hr/>
A = [1; 2|3; 4|5; 6]'- first matrix
B = [9; 8|7; 6|5; 4]'- second matrix
C = fprod(A; B)'- the Frobenius product of matrices A and B

'<p><b>Kprod</b>(<em>first matrix</em>; <em>second matrix</em>)</p><hr/>
A = [1; 2|3; 4]'- first matrix
B = [5; 6; 7|8; 9; 10]'- second matrix
C = kprod(A; B)'- the Kronecker product of matrices A and B

'<p><b>Mnorm_1</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
mnorm_1(A)'- the L1 (Manhattan or taxicab) norm of matrix A

'<p><b>Mnorm</b>(<em>matrix</em>) or <b>Mnorm_2</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
mnorm(A)' or
mnorm_2(A)'- the L2 (spectral) norm of matrix A

'<p><b>Mnorm_е</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
mnorm_e(A)'- the Frobenius (a.k.a. Euclidean) norm of matrix A

'<p><b>Mnorm_i</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
mnorm_i(A)'- the L∞ (infinity) norm of matrix A

'<p><b>Cond_1</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
cond_1(A)'- condition number based on the L1 norm of matrix A

'<p><b>Cond</b>(<em>matrix</em>) or <b>Cond_2</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
cond(A)' or
cond_2(A)'- condition number based on the L2 norm of matrix A

'<p><b>Cond_е</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
cond_e(A)'- condition number based on  the Frobenius norm of matrix A

'<p><b>Cond_i</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
cond_i(A)'- condition number based on the L∞ norm of matrix A

'<p><b>Det</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
det(A)'- the determinant of matrix A

'<p><b>Rank</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
rank(A)'- the rank of matrix A

'<p><b>Trace</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
trace(A)'- the trace of matrix A

'<p><b>Transp</b>(<em>matrix</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]
transp(A)'- the transpose of matrix A

'<p><b>Adj</b>(<em>matrix</em>)</p><hr/>
A = [1; 2|3; 4]
adj(A)'- the adjugate of matrix A
D = det(A)'- the determinant of matrix A
A_I = inverse(A)'- the inverse of matrix A
A_I*D'- the inverse multiplied by the determinant shoud give the adjugate

'<p><b>Cofactor</b>(<em>matrix</em>)</p><hr/>
A = [1; 2|3; 4]
C = cofactor(A)'- the cofactor of matrix A
transp(C)'- the transpose of the cofactor shoud give the adjugate'
adj(A)

'<p><b>Eigenvals</b>(<em>matrix</em>)</p><hr/>
 A = copy( _
    [4; 12; -16| _
    12; 37; -43| _
    - 16; -43; 98]; _
    symmetric(3); 1; 1)'- creates a symmetric matrix by copying a general initializer
eigenvals(A)' - the eigenvalues of matrix A

'<p><b>Eigenvecs</b>(<em>matrix</em>)</p><hr/>
 A = copy( _
    [4; 12; -16| _
    12; 37; -43| _
    - 16; -43; 98]; _
    symmetric(3); 1; 1)'- creates a symmetric matrix by copying a general initializer
eigenvecs(A)' - the eigenvectors of matrix A

'<p><b>Eigen</b>(<em>matrix</em>)</p><hr/>
 A = copy( _
    [4; 12; -16| _
    12; 37; -43| _
    - 16; -43; 98]; _
    symmetric(3); 1; 1)' creates symmetric matrix by copying a general initializer
eigen(A)' - the eigenvalues (first column) and eigenvectors (other columns) of matrix A

'<p><b>Cholesky</b>(<em>matrix</em>)</p><hr/>
 A = copy( _
    [4; 12; -16| _
    12; 37; -43| _
    - 16; -43; 98]; _
    symmetric(3); 1; 1)'- creates a symmetric matrix by copying a general initializer
LT = cholesky(A)'- the upper triangular matrix LT by Cholesky decomposition
L = transp(LT)'- the lower triangular matrix L
L*LT'- check: multiplying both matrices should give the original matrix

'<p><b>LU</b>(<em>matrix</em>)</p><hr/>
 A = [4; 12; -16|12; 37; -43|-16; -43; 98]'- creates general matrix
LU = lu(A)'- the combined matrix by LU decomposition
ind'- the index permutation vector
D = not(identity(3))'- a helper matrix to remove the diagonal elements from L

L = hprod(mfill(ltriang(3); 1); LU)^D'- extracts the lower triangular matrix
U = hprod(mfill(utriang(3); 1); LU)'- extracts the upper triangular matrix
extract_rows(L*U; order(ind))'- check: multiplying both matrices and reordering by the permutation vector should give the original matrix

'<p><b>QR</b>(<em>matrix</em>)</p><hr/>
A = [4; 12; -16|12; 37; -43|-16; -43; 98]'- creates a general matrix

QR = qr(A)'- the combined QR matrix
Q = submatrix(QR; 1; 3; 1; 3)'- extracts the Q matrix
R = submatrix(QR; 1; 3; 4; 6)'- extracts the R matrix
Q*R'- check: multiplying both matrices should give the original matrix

'<p><b>SVD</b>(<em>matrix</em>)</p><hr/>
A = [4; 12; -16|12; 37; -43|-16; -43; 98]'- creates a general matrix
SVD = svd(A)'- the combined UΣV matrix, obtained by singular value decomposition
U = submatrix(SVD; 1; 3; 1; 3)'- extracts the U matrix
V = submatrix(SVD; 1; 3; 5; 7)'- extracts the V matrix
σ = col(SVD; 4)'- extracts the singular values
Σ = vec2diag(σ)'- composes the singular value matrix
'Multiplying U,Σ and V may not give the original matrix A, due to the sign ambiguity problem

'<p><b>Inverse</b>(<em>matrix</em>)</p><hr/>
A = [4; 12; -16|12; 37; -43|-16; -43; 98]'- creates a general matrix
B = inverse(A)'- the inverse of A
A*B'- check: multiplying both matrices should give the identity matrix

'<p><b>Lsolve</b>(<em>matrix</em>, <em>vector</em>)</p><hr/>
A = [8; 6; -4|6; 12; -3|-4; -3; 9]'- creates a general matrix
b = [10; 20; 30]'- the right hand side vector
x = lsolve(A; b)'- the solution vector obtained by LU (LDLT) decomposition
A*x'- check: multiplying the matrix by the solution vector should give the right hand side vector

'<p><b>Clsolve</b>(<em>matrix</em>, <em>vector</em>)</p><hr/>
A = copy([8; 6; -4|6; 12; -3|-4; -3; 9]; _
    symmetric(3); 1; 1)'- creates a symmetric matrix
b = [10; 20; 30]'- the right hand side vector
x = clsolve(A; b)'- the solution vector obtained by Cholesky decomposition
A*x'- check: multiplying the matrix by the solution vector should give the right hand side vector

'<p><b>Msolve</b>(<em>matrix</em>, <em>matrix</em>)</p><hr/>
A = [8; 6; -4|6; 12; -3|-4; -3; 9]'- creates a general coefficients matrix
B = join_cols([10; 20; 30]; [40; 50; 60])'- the right hand side matrix
X = msolve(A; B)'- the solution matrix obtained by LU (LDLT) decomposition
A*X'- check: multiplying the coefficients matrix by the solution matrix should give the right hand side matrix

'<p><b>Cmsolve</b>(<em>matrix</em>, <em>matrix</em>)</p><hr/>
A = copy([8; 6; -4|6; 12; -3|-4; -3; 9]; _
    symmetric(3); 1; 1)'- creates a symmetric coefficients  matrix
B = join_cols([10; 20; 30]; [40; 50; 60])'- the right hand side matrix
X = cmsolve(A; B)'- the solution matrix obtained by Cholesky decomposition
A*X'- check: multiplying the coefficients matrix by the solution matrix should give the right hand side matrix

#rad
'Trigonometric:<hr/>
x = [0; 30; 45|60; 90; 180]*(π/180)
sin(x)'- sine
cos(x)'- cosine
tan(x)'- tangent
csc(x)'- cosecant
sec(x)'- secant
cot(x)'- cotangent

'Hyperbolic:<hr/>
x = [-0.5; 0|0.5; 1]
sinh(x)'- hyperbolic sine
cosh(x)'- hyperbolic cosine
tanh(x)'- hyperbolic tangent
csch(x)'- hyperbolic cosecant
sech(x)'- hyperbolic secant
coth(x)'- hyperbolic cotangent

'Inverse trigonometric:<hr/>
x = [-0.5; 0; 0.5|sqrt(2)/2; sqrt(3)/2; 1]
y = [1; sqrt(3)/2; sqrt(2)/2|0.5; 0; -0.5]
asin(x)'- inverse sine
acos(x)'- inverse cosine
atan(x)'- inverse tangent
atan2(x; y)'- the angle whose tangent is the quotient of y and x
acsc(1/x)'- inverse cosecant
asec(1/x)'- inverse secant
acot(x)'- inverse cotangent

'Inverse hyperbolic:<hr/>
x = [1; 2|4; 8]
asinh(x)'- inverse hyperbolic sine
acosh(x)'- inverse hyperbolic cosine
atanh(x/5)'- inverse hyperbolic tangent
acsch(1/x)'- inverse hyperbolic cosecant
asech(1/x)'- inverse hyperbolic secant
acoth(5/x)'- inverse hyperbolic cotangent

'Logarithmic, exponential and roots:<hr/>
log(x)'- decimal logarithm
ln(x)'- natural logarithm
log_2(x)'- binary logarithm
exp(x)'- natural exponent = eˣ
sqr(x)'- square root
cbrt(x)'- cubic root
root(x; 3)'- n-th root

'Rounding:<hr/>
round(x)'- round to the nearest integer
floor(x)'- round to the smaller integer(towards - ∞)
ceiling(x)'- round to the greater integer(towards + ∞)
trunc(x)'- round to the smaller integer(towards zero)

'Integer:<hr/>
x
y = x + 2
mod(x; y)'- the remainder of an integer division
gcd(y)'- the greatest common divisor of several integers
lcm(y)'- the least common multiple of several integers

'Aggregate and interpolation:<hr />
A = [0; 2; 4|6; 8; 12]
b = [5; 3; 1]
min(4; A; 7; b; 10; 11)'- minimum of multiple values
max(4; A; 7; b; 10; 11)'- maximum of multiple values
sum(4; A; 7; b; 10; 11)'- sum of multiple values
sumsq(4; A; 7; b; 10; 11)'- sum of squares
srss(4; A; 7; b; 10; 11)'- square root of sum of squares
average(4; A; 7; b; 10; 11)'- average of multiple values
product(4; A; 7; b; 10; 11)'- product of multiple values
mean(4; A; 7; b; 10; 11)'- geometric mean
take(5; A)'- the 5-th element from the matrix, linearized to list by rows
line(5.5; A)'- linear interpolation along the linearized matrix
spline(5.5; A)'- Hermite spline interpolation along the linearized matrix
take(2; 2; A)'- the element on row 2 and column 2
line(1.5; 2.5; A)'- double linear interpolation
spline(1.5; 2.5; A)'- double Hermite spline interpolation
Rendered Output:

Hprod(first matrix; second matrix)


A = [1; 2 | 3; 4 | 5; 6] = 12 34 56 - first matrix

B = [9; 8 | 7; 6 | 5; 4] = 98 76 54 - second matrix

C = hprod ( A; B )  = 916 2124 2524 - The Hadamard product of matrices A and B

 

Fprod(first matrix; second matrix)


A = [1; 2 | 3; 4 | 5; 6] = 12 34 56 - first matrix

B = [9; 8 | 7; 6 | 5; 4] = 98 76 54 - second matrix

C = fprod ( A; B )  = 119 - the Frobenius product of matrices A and B

 

Kprod(first matrix; second matrix)


A = [1; 2 | 3; 4] = 12 34 - first matrix

B = [5; 6; 7 | 8; 9; 10] = 567 8910 - second matrix

C = kprod ( A; B )  = 567101214 8910161820 151821202428 242730323640 - the Kronecker product of matrices A and B

 

Mnorm_1(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

mnorm1 ( A )  = 18 - the L1 (Manhattan or taxicab) norm of matrix A

 

Mnorm(matrix) or Mnorm_2(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

mnorm ( A )  = 16.85 or

mnorm2 ( A )  = 16.85 - the L2 (spectral) norm of matrix A

 

Mnorm_е(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

mnorme ( A )  = 16.88 - the Frobenius (a.k.a. Euclidean) norm of matrix A

 

Mnorm_i(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

mnormi ( A )  = 24 - the L∞ (infinity) norm of matrix A

 

Cond_1(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

cond1 ( A )  = 6.49×1017 - condition number based on the L1 norm of matrix A

 

Cond(matrix) or Cond_2(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

cond ( A )  = 3.43×1017 or

cond2 ( A )  = 3.43×1017 - condition number based on the L2 norm of matrix A

 

Cond_е(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

conde ( A )  = 4.56×1017 - condition number based on the Frobenius norm of matrix A

 

Cond_i(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

condi ( A )  = 8.65×1017 - condition number based on the L∞ norm of matrix A

 

Det(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

det ( A )  = 6.66×10-16 - the determinant of matrix A

 

Rank(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

rank ( A )  = 2 - the rank of matrix A

 

Trace(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

trace ( A )  = 15 - the trace of matrix A

 

Transp(matrix)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789

transp ( A )  = 147 258 369 - the transpose of matrix A

 

Adj(matrix)


A = [1; 2 | 3; 4] = 12 34

adj ( A )  = 4-2 -31 - the adjugate of matrix A

D = det ( A )  = -2 - the determinant of matrix A

AI = inverse ( A )  = -21 1.5-0.5 - the inverse of matrix A

AI · D = AI ·  ( -2 )  = 4-2 -31 - the inverse multiplied by the determinant shoud give the adjugate

 

Cofactor(matrix)


A = [1; 2 | 3; 4] = 12 34

C = cofactor ( A )  = 4-3 -21 - the cofactor of matrix A

transp ( C )  = 4-2 -31 - the transpose of the cofactor shoud give the adjugate

adj ( A )  = 4-2 -31

 

Eigenvals(matrix)


A = copy ( [4; 12; -16 | 12; 37; -43 | -16; -43; 98]; symmetric ( 3 ) ; 1; 1 )  = 412-16 1237-43 -16-4398 - creates a symmetric matrix by copying a general initializer

eigenvals ( A )  = [0.0188 15.5 123.48] - the eigenvalues of matrix A

 

Eigenvecs(matrix)


A = copy ( [4; 12; -16 | 12; 37; -43 | -16; -43; 98]; symmetric ( 3 ) ; 1; 1 )  = 412-16 1237-43 -16-4398 - creates a symmetric matrix by copying a general initializer

eigenvecs ( A )  = 0.963-0.2650.0411 -0.213-0.849-0.484 -0.163-0.4570.874 - the eigenvectors of matrix A

 

Eigen(matrix)


A = copy ( [4; 12; -16 | 12; 37; -43 | -16; -43; 98]; symmetric ( 3 ) ; 1; 1 )  = 412-16 1237-43 -16-4398 creates symmetric matrix by copying a general initializer

eigen ( A )  = 0.01880.963-0.2650.0411 15.5-0.213-0.849-0.484 123.48-0.163-0.4570.874 - the eigenvalues (first column) and eigenvectors (other columns) of matrix A

 

Cholesky(matrix)


A = copy ( [4; 12; -16 | 12; 37; -43 | -16; -43; 98]; symmetric ( 3 ) ; 1; 1 )  = 412-16 1237-43 -16-4398 - creates a symmetric matrix by copying a general initializer

LT = cholesky ( A )  = 26-8 015 003 - the upper triangular matrix LT by Cholesky decomposition

L = transp ( LT )  = 200 610 -853 - the lower triangular matrix L

L · LT = 412-16 1237-43 -16-4398 - check: multiplying both matrices should give the original matrix

 

LU(matrix)


A = [4; 12; -16 | 12; 37; -43 | -16; -43; 98] = 412-16 1237-43 -16-4398 - creates general matrix

LU = lu ( A )  = 1237-43 -1.336.3340.67 0.333-0.05260.474 - the combined matrix by LU decomposition

ind = [1 2 0] - the index permutation vector

D = not ( identity ( 3 )  )  = 011 101 110 - a helper matrix to remove the diagonal elements from L

 

L = hprod ( mfill ( ltriang ( 3 ) ; 1 ) ; LU ) D = 100 -1.3310 0.333-0.05261 - extracts the lower triangular matrix

U = hprod ( mfill ( utriang ( 3 ) ; 1 ) ; LU )  = 1237-43 06.3340.67 000.474 - extracts the upper triangular matrix

extractrows ( L · U; order ( ind )  )  = 412-16 1237-43 -16-4398 - check: multiplying both matrices and reordering by the permutation vector should give the original matrix

 

QR(matrix)


A = [4; 12; -16 | 12; 37; -43 | -16; -43; 98] = 412-16 1237-43 -16-4398 - creates a general matrix

 

QR = qr ( A )  = -0.196-0.169-0.966-20.4-57.85105.31 -0.588-0.7680.2540-3.86-24.85 0.784-0.618-0.050800-0.457 - the combined QR matrix

Q = submatrix ( QR; 1; 3; 1; 3 )  = -0.196-0.169-0.966 -0.588-0.7680.254 0.784-0.618-0.0508 - extracts the Q matrix

R = submatrix ( QR; 1; 3; 4; 6 )  = -20.4-57.85105.31 0-3.86-24.85 00-0.457 - extracts the R matrix

Q · R = 412-16 1237-43 -16-4398 - check: multiplying both matrices should give the original matrix

 

SVD(matrix)


A = [4; 12; -16 | 12; 37; -43 | -16; -43; 98] = 412-16 1237-43 -16-4398 - creates a general matrix

SVD = svd ( A )  = -0.1630.213-0.963123.48-0.163-0.4570.874 -0.4570.8490.26515.50.2130.8490.484 0.8740.484-0.04110.0188-0.9630.265-0.0411 - the combined UΣV matrix, obtained by singular value decomposition

U = submatrix ( SVD; 1; 3; 1; 3 )  = -0.1630.213-0.963 -0.4570.8490.265 0.8740.484-0.0411 - extracts the U matrix

V = submatrix ( SVD; 1; 3; 5; 7 )  = -0.163-0.4570.874 0.2130.8490.484 -0.9630.265-0.0411 - extracts the V matrix

σ = col ( SVD; 4 )  = [123.48 15.5 0.0188] - extracts the singular values

Σ = vec2diag ( σ )  = 123.4800 015.50 000.0188 - composes the singular value matrix

Multiplying U,Σ and V may not give the original matrix A, due to the sign ambiguity problem

 

Inverse(matrix)


A = [4; 12; -16 | 12; 37; -43 | -16; -43; 98] = 412-16 1237-43 -16-4398 - creates a general matrix

B = inverse ( A )  = 49.36-13.562.11 -13.563.78-0.556 2.11-0.5560.111 - the inverse of A

A · B = 100 -5.68×10-1410 -2.84×10-1401 - check: multiplying both matrices should give the identity matrix

 

Lsolve(matrix, vector)


A = [8; 6; -4 | 6; 12; -3 | -4; -3; 9] = 86-4 612-3 -4-39 - creates a general matrix

b = [10; 20; 30] = [10 20 30] - the right hand side vector

x = lsolve ( A; b )  = [2.5 1.67 5] - the solution vector obtained by LU (LDLT) decomposition

A · x = [10 20 30] - check: multiplying the matrix by the solution vector should give the right hand side vector

 

Clsolve(matrix, vector)


A = copy ( [8; 6; -4 | 6; 12; -3 | -4; -3; 9]; symmetric ( 3 ) ; 1; 1 )  = 86-4 612-3 -4-39 - creates a symmetric matrix

b = [10; 20; 30] = [10 20 30] - the right hand side vector

x = clsolve ( A; b )  = [2.5 1.67 5] - the solution vector obtained by Cholesky decomposition

A · x = [10 20 30] - check: multiplying the matrix by the solution vector should give the right hand side vector

 

Msolve(matrix, matrix)


A = [8; 6; -4 | 6; 12; -3 | -4; -3; 9] = 86-4 612-3 -4-39 - creates a general coefficients matrix

B = joincols ( [10; 20; 30]; [40; 50; 60] )  = 1040 2050 3060 - the right hand side matrix

X = msolve ( A; B )  = 2.58.71 1.672.67 511.43 - the solution matrix obtained by LU (LDLT) decomposition

A · X = 1040 2050 3060 - check: multiplying the coefficients matrix by the solution matrix should give the right hand side matrix

 

Cmsolve(matrix, matrix)


A = copy ( [8; 6; -4 | 6; 12; -3 | -4; -3; 9]; symmetric ( 3 ) ; 1; 1 )  = 86-4 612-3 -4-39 - creates a symmetric coefficients matrix

B = joincols ( [10; 20; 30]; [40; 50; 60] )  = 1040 2050 3060 - the right hand side matrix

X = cmsolve ( A; B )  = 2.58.71 1.672.67 511.43 - the solution matrix obtained by Cholesky decomposition

A · X = 1040 2050 3060 - check: multiplying the coefficients matrix by the solution matrix should give the right hand side matrix

 

Trigonometric:


x = [0; 30; 45 | 60; 90; 180] · π180 = [0; 30; 45 | 60; 90; 180] · 3.14180 = 00.5240.785 1.051.573.14

sin ( x )  = 00.50.707 0.86610 - sine

cos ( x )  = 10.8660.707 0.50-1 - cosine

tan ( x )  = 00.5771 1.731.63×10160 - tangent

csc ( x )  = +∞21.41 1.1518165619676597685 - cosecant

sec ( x )  = 11.151.41 21.63×1016-1 - secant

cot ( x )  = +∞1.731 0.5770-8165619676597685 - cotangent

 

Hyperbolic:


x = [-0.5; 0 | 0.5; 1] = -0.50 0.51

sinh ( x )  = -0.5210 0.5211.18 - hyperbolic sine

cosh ( x )  = 1.131 1.131.54 - hyperbolic cosine

tanh ( x )  = -0.4620 0.4620.762 - hyperbolic tangent

csch ( x )  = -1.92+∞ 1.920.851 - hyperbolic cosecant

sech ( x )  = 0.8871 0.8870.648 - hyperbolic secant

coth ( x )  = -2.16+∞ 2.161.31 - hyperbolic cotangent

 

Inverse trigonometric:


x = [-0.5; 0; 0.5 |     22;     32; 1] = -0.500.5 0.7070.8661

y = [1;     32;     22 | 0.5; 0; -0.5] = 10.8660.707 0.50-0.5

asin ( x )  = -0.52400.524 0.7851.051.57 - inverse sine

acos ( x )  = 2.091.571.05 0.7850.5240 - inverse cosine

atan ( x )  = -0.46400.464 0.6150.7140.785 - inverse tangent

atan2 ( x; y )  = 2.031.570.955 0.6150-0.464 - the angle whose tangent is the quotient of y and x

acsc(1x) = -0.52400.524 0.7851.051.57 - inverse cosecant

asec(1x) = 2.091.571.05 0.7850.5240 - inverse secant

acot ( x )  = -1.111.571.11 0.9550.8570.785 - inverse cotangent

 

Inverse hyperbolic:


x = [1; 2 | 4; 8] = 12 48

asinh ( x )  = 0.8811.44 2.092.78 - inverse hyperbolic sine

acosh ( x )  = 01.32 2.062.77 - inverse hyperbolic cosine

atanh(x5) = 0.2030.424 1.1 Undefined - inverse hyperbolic tangent

acsch(1x) = 0.8811.44 2.092.78 - inverse hyperbolic cosecant

asech(1x) = 01.32 2.062.77 - inverse hyperbolic secant

acoth(5x) = 0.2030.424 1.1 Undefined - inverse hyperbolic cotangent

 

Logarithmic, exponential and roots:


log ( x )  = 00.301 0.6020.903 - decimal logarithm

ln ( x )  = 00.693 1.392.08 - natural logarithm

log2 ( x )  = 01 23 - binary logarithm

exp ( x )  = 2.727.39 54.62980.96 - natural exponent = eˣ

   x = 11.41 22.83 - square root

3  x = 11.26 1.592 - cubic root

3  x = 11.26 1.592 - n-th root

 

Rounding:


round ( x )  = 12 48 - round to the nearest integer

floor ( x )  = 12 48 - round to the smaller integer(towards - ∞)

ceiling ( x )  = 12 48 - round to the greater integer(towards + ∞)

trunc ( x )  = 12 48 - round to the smaller integer(towards zero)

 

Integer:


x = 12 48

y = x + 2 = 34 610

mod ( x; y )  = 12 48 - the remainder of an integer division

gcd ( y )  = 1 - the greatest common divisor of several integers

lcm ( y )  = 60 - the least common multiple of several integers

 

Aggregate and interpolation:


A = [0; 2; 4 | 6; 8; 12] = 024 6812

b = [5; 3; 1] = [5 3 1]

min ( 4; A; 7; b; 10; 11 )  = 0 - minimum of multiple values

max ( 4; A; 7; b; 10; 11 )  = 12 - maximum of multiple values

sum ( 4; A; 7; b; 10; 11 )  = 73 - sum of multiple values

sumsq ( 4; A; 7; b; 10; 11 )  = 585 - sum of squares

srss ( 4; A; 7; b; 10; 11 )  = 24.19 - square root of sum of squares

average ( 4; A; 7; b; 10; 11 )  = 5.62 - average of multiple values

product ( 4; A; 7; b; 10; 11 )  = 0 - product of multiple values

mean ( 4; A; 7; b; 10; 11 )  = 0 - geometric mean

take ( 5; A )  = 8 - the 5-th element from the matrix, linearized to list by rows

line ( 5.5; A )  = 10 - linear interpolation along the linearized matrix

spline ( 5.5; A )  = 9.81 - Hermite spline interpolation along the linearized matrix

take ( 2; 2; A )  = 8 - the element on row 2 and column 2

line ( 1.5; 2.5; A )  = 6.5 - double linear interpolation

spline ( 1.5; 2.5; A )  = 6.41 - double Hermite spline interpolation

Matrix Structural Functions

Structural plumbing for matrices: \(n_{rows}\), \(n_{cols}\), resize, join, reshape, submatrix and the slicing helpers that feed the rest of the toolkit.

Code:
'<style>em {font-family:"Times New Roman";}</style>
'<p><b>N_Rows</b>(<em>matrix</em>)</p><hr/>
A = [1; 2|3; 4|5; 6]
n_rows(A)'- the number of rows in A

'<p><b>N_Cols</b>(<em>matrix</em>)</p><hr/>
A = [1|2; 3|4; 5; 6]
n_cols(A)'- the number of columns in A

'<p><b>Mresize</b>(<em>matrix</em>; <em>m</em>; <em>n</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]'- creates a general type matrix
B = mresize(A; 2; 4)'- resizes to a general type as well
A'- the original matrix has changed
A = diagonal(3; 5)'- creates a diagonal type matrix
B = mresize(A; 2; 4)'- resizes to a general type
A'- the original matrix remains unchanged

'<p><b>Mfill</b>(<em>matrix</em>; <em>value</em>)</p><hr/>
A = matrix(2; 3)'- creates an empty matrix A
B = mfill(A; 1)'- fills A with ones and assigns the result to B
B.(1; 2) = 2'- changes a single value in B which references A
A'- A has also changed
L = mfill(ltriang(4); 2)'- special matrices are filled only inside the designated area

'<p><b>Fill_Row</b>(<em>matrix</em>; <em>row index</em>; <em>value</em>)</p><hr/>
A = matrix(3; 4)'- creates a general matrix
fill_row(A; 2; 1)'- fills the 2-nd row with value of 1
L = utriang(4)' - creates an upper triangular matrix
$Repeat{fill_row(L; k; k) @ k = 1 : n_rows(L)}' - fills all rows
L' - only the designated area to the type (the upper triangle) is filled

'<p><b>Fill_Col</b>(<em>matrix</em>; <em>column index</em>; <em>value</em>)</p><hr/>
A = matrix(3; 4)'- creates a general matrix
fill_col(A; 2; 1)'- fills the 2nd column with value of 1
B = symmetric(4)'- creates a symmetric matrix
fill_col(B; 2; 1)' - the respective row is also filled to preserve symmetry

'<p><b>Copy</b>(<em>source matrix</em>; <em>target matrix</em>; <em>row index</em>; <em>column index</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6]'- creates a 2x3 rectangular source matrix
B = mfill(matrix(3; 4); -1)'- creates a 3x4 rectangular target  matrix and fills it with -1
copy(A; B; 1; 1)'- copies A to B at indexes (1,1) of B
copy(A; B; 2; 2)'- copies A to B at indexes (2,2) of B
B'- the obtained target matrix

'<p><b>Add</b>(<em>source matrix</em>; <em>target matrix</em>; <em>row index</em>; <em>column index</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6]'- creates a 2x3 rectangular source matrix
B = mfill(matrix(3; 4); -1)'- creates a 3x4 rectangular target  matrix and fills it with -1
add(A; B; 1; 1)'- adds A to B at indexes (1,1) of B
add(A; B; 2; 2)'- adds A to B at indexes (2,2) of B
B'- the obtained target matrix

'<p><b>Row</b>(<em>matrix</em>; <em>row index</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]'- creates a 3x3 general matrix
row(A; 3)'- extracts the 3-rd row into a new vector

'<p><b>Col</b>(<em>matrix</em>; <em>column index</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]'- creates a 3x3 general matrix
col(A; 2)'- extracts the 2-nd column into a new vector

'<p><b>Extract_Rows</b>(<em>matrix</em>; <em>row indexes vector</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]'- creates a 3x3 general matrix
extract_rows(A; [1; 2; 1])'- extracts rows 1, 2 and 1 into a new matrix

'<p><b>Extract_Cols</b>(<em>matrix</em>; <em>column index vector</em>)</p><hr/>
A = [1; 2; 3|4; 5; 6|7; 8; 9]'- creates a 3x3 general matrix
extract_cols(A; [3; 2; 1])'- extracts columns 3, 2 and 1 into a new matrix

'<p><b>Diag2vec</b>(<em>matrix</em>)</p><hr/>
A = [1; 2|3; 4|5; 6; 7|8; 9; 10]'- creates a 4x3 rectangular matrix
diag2vec(A)'- extracts the elements along the main diagonal into a new vector

'<p><b>Submatrix</b>(<em>matrix</em>; <em>start row</em>; <em>end row</em>; <em>start column</em>; <em>end column</em>)</p><hr/>
A = [1; 2; 3; 4| _
     5; 6; 7; 8| _
     9; 10; 11; 12| _
    13; 14; 15; 16]'- creates a 4x4 general matrix
submatrix(A; 2; 3; 2; 4)'- extracts the values between rows 2 and 3 and between columns 2 and 4 into a new matrix
Rendered Output:

N_Rows(matrix)


A = [1; 2 | 3; 4 | 5; 6] = 12 34 56

nrows ( A )  = 3 - the number of rows in A

 

N_Cols(matrix)


A = [1 | 2; 3 | 4; 5; 6] = 100 230 456

ncols ( A )  = 3 - the number of columns in A

 

Mresize(matrix; m; n)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789 - creates a general type matrix

B = mresize ( A; 2; 4 )  = 1230 4560 - resizes to a general type as well

A = 1230 4560 - the original matrix has changed

A = diagonal ( 3; 5 )  = 500 050 005 - creates a diagonal type matrix

B = mresize ( A; 2; 4 )  = 500 050 005 - resizes to a general type

A = 500 050 005 - the original matrix remains unchanged

 

Mfill(matrix; value)


A = matrix ( 2; 3 )  = 000 000 - creates an empty matrix A

B = mfill ( A; 1 )  = 111 111 - fills A with ones and assigns the result to B

B1,2 = 2 - changes a single value in B which references A

A = 121 111 - A has also changed

L = mfill ( ltriang ( 4 ) ; 2 )  = 2000 2200 2220 2222 - special matrices are filled only inside the designated area

 

Fill_Row(matrix; row index; value)


A = matrix ( 3; 4 )  = 0000 0000 0000 - creates a general matrix

fillrow ( A; 2; 1 )  = 0000 1111 0000 - fills the 2-nd row with value of 1

L = utriang ( 4 )  = 0000 0000 0000 0000 - creates an upper triangular matrix

$Repeat{fillrow ( L; k; k )  for k = 1...nrows ( L ) } = 1111 0222 0033 0004 - fills all rows

L = 1111 0222 0033 0004 - only the designated area to the type (the upper triangle) is filled

 

Fill_Col(matrix; column index; value)


A = matrix ( 3; 4 )  = 0000 0000 0000 - creates a general matrix

fillcol ( A; 2; 1 )  = 0100 0100 0100 - fills the 2nd column with value of 1

B = symmetric ( 4 )  = 0000 0000 0000 0000 - creates a symmetric matrix

fillcol ( B; 2; 1 )  = 0000 0111 0100 0100 - the respective row is also filled to preserve symmetry

 

Copy(source matrix; target matrix; row index; column index)


A = [1; 2; 3 | 4; 5; 6] = 123 456 - creates a 2x3 rectangular source matrix

B = mfill ( matrix ( 3; 4 ) ; -1 )  = -1-1-1-1 -1-1-1-1 -1-1-1-1 - creates a 3x4 rectangular target matrix and fills it with -1

copy ( A; B; 1; 1 )  = 123-1 456-1 -1-1-1-1 - copies A to B at indexes (1,1) of B

copy ( A; B; 2; 2 )  = 123-1 4123 -1456 - copies A to B at indexes (2,2) of B

B = 123-1 4123 -1456 - the obtained target matrix

 

Add(source matrix; target matrix; row index; column index)


A = [1; 2; 3 | 4; 5; 6] = 123 456 - creates a 2x3 rectangular source matrix

B = mfill ( matrix ( 3; 4 ) ; -1 )  = -1-1-1-1 -1-1-1-1 -1-1-1-1 - creates a 3x4 rectangular target matrix and fills it with -1

add ( A; B; 1; 1 )  = 012-1 345-1 -1-1-1-1 - adds A to B at indexes (1,1) of B

add ( A; B; 2; 2 )  = 012-1 3572 -1345 - adds A to B at indexes (2,2) of B

B = 012-1 3572 -1345 - the obtained target matrix

 

Row(matrix; row index)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789 - creates a 3x3 general matrix

row ( A; 3 )  = [7 8 9] - extracts the 3-rd row into a new vector

 

Col(matrix; column index)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789 - creates a 3x3 general matrix

col ( A; 2 )  = [2 5 8] - extracts the 2-nd column into a new vector

 

Extract_Rows(matrix; row indexes vector)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789 - creates a 3x3 general matrix

extractrows ( A; [1; 2; 1] )  = 123 456 123 - extracts rows 1, 2 and 1 into a new matrix

 

Extract_Cols(matrix; column index vector)


A = [1; 2; 3 | 4; 5; 6 | 7; 8; 9] = 123 456 789 - creates a 3x3 general matrix

extractcols ( A; [3; 2; 1] )  = 321 654 987 - extracts columns 3, 2 and 1 into a new matrix

 

Diag2vec(matrix)


A = [1; 2 | 3; 4 | 5; 6; 7 | 8; 9; 10] = 120 340 567 8910 - creates a 4x3 rectangular matrix

diag2vec ( A )  = [1 4 7] - extracts the elements along the main diagonal into a new vector

 

Submatrix(matrix; start row; end row; start column; end column)


A = [1; 2; 3; 4 | 5; 6; 7; 8 | 9; 10; 11; 12 | 13; 14; 15; 16] = 1234 5678 9101112 13141516 - creates a 4x4 general matrix

submatrix ( A; 2; 3; 2; 4 )  = 678 101112 - extracts the values between rows 2 and 3 and between columns 2 and 4 into a new matrix

Matrix Operators

Reference for matrix and matrix-vector operators: element-wise vs. algebraic multiplication, comparison and logical operators broadcast across whole grids.

Code:
'<h4>Matrix-matrix</h4>
A = [0; 1; 2|3; 4; 5]', 'B = [11; 10; 9|8; 7; 6]
'Arithmetic:
A!'- factorial
A^B'- exponentiation
A/B'- floating point division
A\B'- integer division
A÷B'- division bar
AB'- modulo(⦼, remainder)
hprod(A; B)'- element-wise multiplication
A - B'- subtraction
A + B'- addition
'Relational (comparison):
A  B'- equal to
A  B'- unequal to
A < B'- less then
A > B'- greater than
A  B'- less or equal
A  B'- greater or equal
'Logical:
A  B'- logical "and"
A  B'- logical "or"
A  B'- logical "xor"
'Matrix multiplication
A = [1; 2; 3|4; 5; 6]
B = [6; 5|4; 3|2; 1]
A*B

'<h4>Matrix-vector</h4>
A = [0|1|2|3|4|5]', 'b = [11; 10; 9; 8; 7; 6]
'Arithmetic:
A^b'- exponentiation
A/b'- floating point division
A\b'- integer division
A÷b'- division bar
Ab'- modulo(⦼, remainder)
hprod(A; b)'- element-wise multiplication
A - b'- subtraction
A + b'- addition
'Relational (comparison):
A  b'- equal to
A  b'- unequal to
A < b'- less then
A > b'- greater than
A  b'- less or equal
A  b'- greater or equal
'Logical:
A  b'- logical "and"
A  b'- logical "or"
A  b'- logical "xor"
'Matrix multiplication
A*transp(b)
transp(A)*b

'<h4>Vector-matrix</h4>
a = [0; 1; 2; 3; 4; 5]', 'B = [11|10|9|8|7|6]
'Arithmetic:
a^B'- exponentiation
a/B'- floating point division
a\B'- integer division
a÷B'- division bar
aB'- modulo(⦼, remainder)
hprod(a; b)'- element-wise multiplication
a - B'- subtraction
a + B'- addition
'Relational (comparison):
a  B'- equal to
a  B'- unequal to
a < B'- less then
a > B'- greater than
a  B'- less or equal
a  B'- greater or equal
'Logical:
a  B'- logical "and"
a  B'- logical "or"
a  B'- logical "xor"
'Matrix multiplication
a*transp(b)
transp(a)*b

'<h4>Matrix-scalar</h4>
A = [0; 1; 2|3; 4; 5]', 'b = 2
'Arithmetic:
A^2'- exponentiation
A/2'- floating point division
A\2'- integer division
A÷2'- division bar
A2'- modulo(⦼, remainder)
A - 2'- subtraction
A + 2'- addition
'Relational (comparison):
A  2'- equal to
A  2'- unequal to
A < 2'- less then
A > 2'- greater than
A  2'- less or equal
A  2'- greater or equal
'Logical:
A  2'- logical "and"
A  2'- logical "or"
A  2'- logical "xor"

'<h4>Scalar-matrix</h4>
a = 2', 'B = [11; 10; 9|8; 7; 6]
'Arithmetic:
2^B'-exponentiation
2/B'- floating point division
2\B'- integer division
2÷B'- division bar
2B'- modulo(⦼, remainder)
2*B'- multiplication
2 - B'- subtraction
2 + B'- addition
'Relational (comparison):
2  B'- equal to
2  B'- unequal to
2 < B'- less then
2 > B'- greater than
2  B'- less or equal
2  B'- greater or equal
'Logical:
2  B'- logical "and"
2  B'- logical "or
2  B'- logical "xor"
Rendered Output:
Matrix-matrix

A = [0; 1; 2 | 3; 4; 5] = 012 345 , B = [11; 10; 9 | 8; 7; 6] = 11109 876

Arithmetic:

A! = 112 624120 - factorial

AB = 01512 65611638415625 - exponentiation

AB = 00.10.222 0.3750.5710.833 - floating point division

A\B = 000 000 - integer division

A / B = 00.10.222 0.3750.5710.833 - division bar

A mod B = 012 345 - modulo(⦼, remainder)

hprod ( A; B )  = 01018 242830 - element-wise multiplication

AB = -11-9-7 -5-3-1 - subtraction

A + B = 111111 111111 - addition

Relational (comparison):

AB = 000 000 - equal to

AB = 111 111 - unequal to

A < B = 111 111 - less then

A > B = 000 000 - greater than

AB = 111 111 - less or equal

AB = 000 000 - greater or equal

Logical:

A and B = 011 111 - logical "and"

A or B = 111 111 - logical "or"

A xor B = 100 000 - logical "xor"

Matrix multiplication

A = [1; 2; 3 | 4; 5; 6] = 123 456

B = [6; 5 | 4; 3 | 2; 1] = 65 43 21

A · B = 2014 5641

 

Matrix-vector

A = [0 | 1 | 2 | 3 | 4 | 5] = 0 1 2 3 4 5 , b = [11; 10; 9; 8; 7; 6] = [11 10 9 8 7 6]

Arithmetic:

Ab = 0 1 512 6561 16384 15625 - exponentiation

Ab = 0 0.1 0.222 0.375 0.571 0.833 - floating point division

A\b = 0 0 0 0 0 0 - integer division

A / b = 0 0.1 0.222 0.375 0.571 0.833 - division bar

A mod b = 0 1 2 3 4 5 - modulo(⦼, remainder)

hprod ( A; b )  = 0 10 18 24 28 30 - element-wise multiplication

Ab = -11 -9 -7 -5 -3 -1 - subtraction

A + b = 11 11 11 11 11 11 - addition

Relational (comparison):

Ab = 0 0 0 0 0 0 - equal to

Ab = 1 1 1 1 1 1 - unequal to

A < b = 1 1 1 1 1 1 - less then

A > b = 0 0 0 0 0 0 - greater than

Ab = 1 1 1 1 1 1 - less or equal

Ab = 0 0 0 0 0 0 - greater or equal

Logical:

A and b = 0 1 1 1 1 1 - logical "and"

A or b = 1 1 1 1 1 1 - logical "or"

A xor b = 1 0 0 0 0 0 - logical "xor"

Matrix multiplication

A · transp ( b )  = 000000 11109876 222018161412 333027242118 444036322824 555045403530

transp ( A )  · b = 110

 

Vector-matrix

a = [0; 1; 2; 3; 4; 5] = [0 1 2 3 4 5] , B = [11 | 10 | 9 | 8 | 7 | 6] = 11 10 9 8 7 6

Arithmetic:

aB = 0 1 512 6561 16384 15625 - exponentiation

aB = 0 0.1 0.222 0.375 0.571 0.833 - floating point division

a\B = 0 0 0 0 0 0 - integer division

a / B = 0 0.1 0.222 0.375 0.571 0.833 - division bar

a mod B = 0 1 2 3 4 5 - modulo(⦼, remainder)

hprod ( a; b )  = 0 10 18 24 28 30 - element-wise multiplication

aB = -11 -9 -7 -5 -3 -1 - subtraction

a + B = 11 11 11 11 11 11 - addition

Relational (comparison):

aB = 0 0 0 0 0 0 - equal to

aB = 1 1 1 1 1 1 - unequal to

a < B = 1 1 1 1 1 1 - less then

a > B = 0 0 0 0 0 0 - greater than

aB = 1 1 1 1 1 1 - less or equal

aB = 0 0 0 0 0 0 - greater or equal

Logical:

a and B = 0 1 1 1 1 1 - logical "and"

a or B = 1 1 1 1 1 1 - logical "or"

a xor B = 1 0 0 0 0 0 - logical "xor"

Matrix multiplication

a · transp ( b )  = 000000 11109876 222018161412 333027242118 444036322824 555045403530

transp ( a )  · b = 110

 

Matrix-scalar

A = [0; 1; 2 | 3; 4; 5] = 012 345 , b = 2

Arithmetic:

A 2 = 014 91625 - exponentiation

A2 = 00.51 1.522.5 - floating point division

A\2 = 001 122 - integer division

A / 2 = 00.51 1.522.5 - division bar

A mod 2 = 010 101 - modulo(⦼, remainder)

A − 2 = -2-10 123 - subtraction

A + 2 = 234 567 - addition

Relational (comparison):

A ≡ 2 = 001 000 - equal to

A ≠ 2 = 110 111 - unequal to

A < 2 = 110 000 - less then

A > 2 = 000 111 - greater than

A ≤ 2 = 111 000 - less or equal

A ≥ 2 = 001 111 - greater or equal

Logical:

A and 2 = 011 111 - logical "and"

A or 2 = 111 111 - logical "or"

A xor 2 = 100 000 - logical "xor"

 

Scalar-matrix

a = 2 , B = [11; 10; 9 | 8; 7; 6] = 11109 876

Arithmetic:

2B = 20481024512 25612864 -exponentiation

2B = 0.1820.20.222 0.250.2860.333 - floating point division

2\B = 000 000 - integer division

2 / B = 0.1820.20.222 0.250.2860.333 - division bar

2 mod B = 222 222 - modulo(⦼, remainder)

2 · B = 222018 161412 - multiplication

2 − B = -9-8-7 -6-5-4 - subtraction

2 + B = 131211 1098 - addition

Relational (comparison):

2 ≡ B = 000 000 - equal to

2 ≠ B = 111 111 - unequal to

2 < B = 111 111 - less then

2 > B = 000 000 - greater than

2 ≤ B = 111 111 - less or equal

2 ≥ B = 000 000 - greater or equal

Logical:

2 and B = 111 111 - logical "and"

2 or B = 111 111 - logical "or

2 xor B = 000 000 - logical "xor"

Spotted an error? Edit these examples.