Matrix | Science @ Science @ MentDB Weak

Matrix and vector
• Matrix computation (Apache Commons Math).
• A matrix is a JSON array of rows: "[[1, 2], [3, 4]]". A vector is a JSON array of numbers: "[1, 2]".
• The indexes start at 1 (as on scientific calculators).
• The rounding noise of the inverse and of the solutions is removed when the rounded result is at least as accurate (0.9999999999999998 -> 1).
• Vector computation. A vector is a JSON array of numbers: "[1, 2, 3]".
• The angles are in radians.
matrix add <json_matrix> <json_matrix2>matrix col <json_matrix> <j>matrix det <json_matrix>matrix diag <json_vector>matrix get <json_matrix> <i> <j>matrix identity <n>matrix inverse <json_matrix>matrix mul <json_matrix> <json_matrix_or_vector>matrix ones <rows> <cols>matrix random <rows> <cols>matrix row <json_matrix> <i>matrix scalar_mul <json_matrix> <k>matrix set <json_matrix> <i> <j> <value>matrix size <json_matrix>matrix solve <json_matrix_a> <json_b>matrix sub <json_matrix> <json_matrix2>matrix trace <json_matrix>matrix transpose <json_matrix>matrix zeros <rows> <cols>matrix cholesky <json_matrix>matrix cond <json_matrix>matrix eigen <json_matrix>matrix lu <json_matrix>matrix norm <json_matrix>matrix norm_frobenius <json_matrix>matrix pinv <json_matrix>matrix pow <json_matrix> <n>matrix qr <json_matrix>matrix rank <json_matrix>matrix rref <json_matrix>matrix svd <json_matrix>vector angle <json_vector> <json_vector2>vector cross <json_vector> <json_vector2>vector dot <json_vector> <json_vector2>vector norm <json_vector>vector unit <json_vector>vector add <json_vector> <json_vector2>vector scale <json_vector> <k>vector sub <json_vector> <json_vector2>

matrix add <json_matrix> <json_matrix2>


Description

Add two matrices of the same size

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
json_matrix2: A matrix: JSON array of rows - String - required

Examples (4)
admin
matrix add "[[1, 2], [3, 4]]" "[[5, 6], [7, 8]]"
mentdb
[[6,8],[10,12]]
3 x 3
admin
matrix add "[[1, 0, 2], [0, 1, 0], [2, 0, 1]]" "[[1, 1, 1], [1, 1, 1], [1, 1, 1]]"
mentdb
[[2,1,3],[1,2,1],[3,1,2]]
Negative values
admin
matrix add "[[1, -1], [0, 2]]" "[[-1, 1], [0, -2]]"
mentdb
[[0,0],[0,0]]
Different sizes: error
admin
matrix add "[[1, 2]]" "[[1], [2]]"
mentdb
Sorry, an error appears (the matrices must have the same size (1x2 and 2x1)).

matrix col <json_matrix> <j>


Description

Get a column of a matrix (index starts at 1), as a vector

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
j: The column (1 to n) - Number - required

Examples (4)
admin
matrix col "[[1, 2], [3, 4]]" 2
mentdb
[2,4]
Third column
admin
matrix col "[[1, 2, 3], [4, 5, 6]]" 3
mentdb
[3,6]
First column
admin
matrix col "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]" 1
mentdb
[1,4,7]
Index out of the matrix: error
admin
matrix col "[[1, 2], [3, 4]]" 3
mentdb
Sorry, an error appears (the column 3 is out of the matrix (1 to 2)).

matrix det <json_matrix>


Description

Get the determinant of a square matrix (an integer matrix gives an integer determinant)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (6)
admin
matrix det "[[1, 2], [3, 4]]"
mentdb
-2
3 x 3
admin
matrix det "[[2, -3, 1], [2, 0, -1], [1, 4, 5]]"
mentdb
49
Singular matrix: 0
admin
matrix det "[[1, 2], [2, 4]]"
mentdb
0
Identity: 1
admin
matrix det (matrix identity 4)
mentdb
1
Triangular matrix: product of the diagonal
admin
matrix det "[[2, 5, 1], [0, 3, 7], [0, 0, 4]]"
mentdb
24
Not square: error
admin
matrix det "[[1, 2, 3], [4, 5, 6]]"
mentdb
Sorry, an error appears (the matrix must be square (2x3)).

matrix diag <json_vector>


Description

Create a diagonal matrix from a vector

Parameters

json_vector: A vector: JSON array of numbers, ex: [1, 2, 3] - String - required

Examples (4)
admin
matrix diag "[1, 2, 3]"
mentdb
[[1,0,0],[0,2,0],[0,0,3]]
Diagonal matrix of 4 values
admin
matrix diag "[2, 3, 5, 7]"
mentdb
[[2,0,0,0],[0,3,0,0],[0,0,5,0],[0,0,0,7]]
Diagonal with zeros
admin
matrix diag "[1, 0, -1]"
mentdb
[[1,0,0],[0,0,0],[0,0,-1]]
One value
admin
matrix diag "[5]"
mentdb
[[5]]

matrix get <json_matrix> <i> <j>


Description

Get a value of a matrix (indexes start at 1)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
i: The row (1 to n) - Number - required
j: The column (1 to n) - Number - required

Examples (4)
admin
matrix get "[[1, 2], [3, 4]]" 2 1
mentdb
3
Element (1, 3)
admin
matrix get "[[1, 2, 3], [4, 5, 6]]" 1 3
mentdb
3
The indices start at 1
admin
matrix get "[[1, 2], [3, 4]]" 1 1
mentdb
1
Out of the matrix: error
admin
matrix get "[[1, 2], [3, 4]]" 3 1
mentdb
Sorry, an error appears (the row 3 is out of the matrix (1 to 2)).

matrix identity <n>


Description

Create the identity matrix n x n

Parameters

n: The size - Number - required

Examples (4)
admin
matrix identity 3
mentdb
[[1,0,0],[0,1,0],[0,0,1]]
2 x 2
admin
matrix identity 2
mentdb
[[1,0],[0,1]]
Size 4
admin
matrix identity 4
mentdb
[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
Size 1
admin
matrix identity 1
mentdb
[[1]]

matrix inverse <json_matrix>


Description

Get the inverse of a square matrix (error if the matrix is singular)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (6)
admin
matrix inverse "[[1, 2], [3, 4]]"
mentdb
[[-2,1],[1.5,-0.5]]
admin
matrix inverse "[[1, 2, 3], [0, 1, 4], [5, 6, 0]]"
mentdb
[[-24,18,5],[20,-15,-4],[-5,4,1]]
3 x 3
admin
matrix inverse "[[2, 0, 0], [0, 4, 0], [0, 0, 8]]"
mentdb
[[0.5,0,0],[0,0.25,0],[0,0,0.125]]
Check: A * inverse(A) = I
admin
matrix mul "[[1, 2], [3, 4]]" (matrix inverse "[[1, 2], [3, 4]]")
mentdb
[[1,0],[0,1]]
Rotation of 90 degrees: the inverse is the transpose
admin
matrix inverse "[[0, -1], [1, 0]]"
mentdb
[[0,1],[-1,0]]
Singular matrix: error
admin
matrix inverse "[[1, 2], [2, 4]]"
mentdb
Sorry, an error appears (the matrix is singular (determinant = 0)).

matrix mul <json_matrix> <json_matrix_or_vector>


Description

Multiply two matrices, or a matrix by a vector (column): the result is then a vector

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
json_matrix_or_vector: A matrix or a vector - String - required

Examples (6)
admin
matrix mul "[[1, 2], [3, 4]]" "[[5, 6], [7, 8]]"
mentdb
[[19,22],[43,50]]
Matrix times vector
admin
matrix mul "[[1, 2], [3, 4]]" "[1, 1]"
mentdb
[3,7]
Rotation of 90 degrees of the vector (1, 0)
admin
matrix mul "[[0, -1], [1, 0]]" "[1, 0]"
mentdb
[0,1]
Rectangular: (2 x 3) x (3 x 2)
admin
matrix mul "[[1, 2, 3], [4, 5, 6]]" "[[1, 0], [0, 1], [1, 1]]"
mentdb
[[4,5],[10,11]]
Rotation of a point by 90 degrees
admin
matrix mul "[[0, -1], [1, 0]]" "[2, 1]"
mentdb
[-1,2]
Wrong sizes: error
admin
matrix mul "[[1, 2], [3, 4]]" "[1, 2, 3]"
mentdb
Sorry, an error appears (the number of columns of the matrix (2) must be equal to the size of the vector (3)).

matrix ones <rows> <cols>


Description

Create a matrix filled with 1

Parameters

rows: The number of rows - Number - required
cols: The number of columns - Number - required

Examples (4)
admin
matrix ones 2 2
mentdb
[[1,1],[1,1]]
3 x 1
admin
matrix ones 3 1
mentdb
[[1],[1],[1]]
Row vector
admin
matrix ones 1 3
mentdb
[[1,1,1]]
Matrix of 2 x 3
admin
matrix ones 2 3
mentdb
[[1,1,1],[1,1,1]]

matrix random <rows> <cols>


Description

Create a matrix of random values in [0, 1[

Parameters

rows: The number of rows - Number - required
cols: The number of columns - Number - required

Examples (3)
admin
matrix random 2 2
mentdb
[[0.3100355736238589,0.20783595291913093],[0.8476659182838927,0.012550597903072558]]
3 x 2 (the result changes each time)
admin
matrix random 3 2
mentdb
[[0.7336323096664192,0.9588240596867678],[0.40548742962834683,0.443526902901052],[0.1160726913934782,0.18012846601976895]]
Determinant of a random matrix (the result changes each time)
admin
matrix det (matrix random 3 3)
mentdb
-0.23265845744408647

matrix row <json_matrix> <i>


Description

Get a row of a matrix (index starts at 1), as a vector

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
i: The row (1 to n) - Number - required

Examples (4)
admin
matrix row "[[1, 2], [3, 4]]" 2
mentdb
[3,4]
First row
admin
matrix row "[[1, 2, 3], [4, 5, 6]]" 1
mentdb
[1,2,3]
Last row
admin
matrix row "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]" 3
mentdb
[7,8,9]
Out of the matrix: error
admin
matrix row "[[1, 2], [3, 4]]" 5
mentdb
Sorry, an error appears (the row 5 is out of the matrix (1 to 2)).

matrix scalar_mul <json_matrix> <k>


Description

Multiply a matrix by a number

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
k: The number - Number - required

Examples (4)
admin
matrix scalar_mul "[[1, 2], [3, 4]]" 2.5
mentdb
[[2.5,5],[7.5,10]]
Opposite matrix
admin
matrix scalar_mul "[[1, -2], [3, 0]]" -1
mentdb
[[-1,2],[-3,0]]
Divide by 2
admin
matrix scalar_mul "[[2, 4], [6, 8]]" 0.5
mentdb
[[1,2],[3,4]]
By 0
admin
matrix scalar_mul "[[1, 2], [3, 4]]" 0
mentdb
[[0,0],[0,0]]

matrix set <json_matrix> <i> <j> <value>


Description

Set a value of a matrix (indexes start at 1): returns the new matrix

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
i: The row (1 to n) - Number - required
j: The column (1 to n) - Number - required
value: The new value - Number - required

Examples (4)
admin
matrix set "[[1, 2], [3, 4]]" 1 2 9
mentdb
[[1,9],[3,4]]
Change the element (2, 2)
admin
matrix set (matrix identity 2) 2 2 5
mentdb
[[1,0],[0,5]]
Change a value
admin
matrix set "[[1, 2, 3], [4, 5, 6]]" 2 3 0
mentdb
[[1,2,3],[4,5,0]]
Out of the matrix: error
admin
matrix set "[[1, 2], [3, 4]]" 3 3 1
mentdb
Sorry, an error appears (the row 3 is out of the matrix (1 to 2)).

matrix size <json_matrix>


Description

Get the size of a matrix [rows, columns]

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix size "[[1, 2, 3], [4, 5, 6]]"
mentdb
[2,3]
Column vector
admin
matrix size "[[1], [2], [3]]"
mentdb
[3,1]
Square matrix
admin
matrix size (matrix identity 4)
mentdb
[4,4]
One row
admin
matrix size "[[1, 2, 3, 4]]"
mentdb
[1,4]

matrix solve <json_matrix_a> <json_b>


Description

Solve the linear system A.X = B.
- A square: exact solution (LU), error if A is singular.
- A with more rows than columns: least squares solution (QR).
B can be a vector (the result is a vector) or a matrix (several systems at once).

Parameters

json_matrix_a: The matrix A - String - required
json_b: The vector or the matrix B - String - required

Examples (6)
admin
matrix solve "[[1, 1, 1], [0, 2, 5], [2, 5, -1]]" "[6, -4, 27]"
mentdb
[5,3,-2]
admin
matrix solve "[[2, 1], [1, 3]]" "[3, 5]"
mentdb
[0.8,1.4]
Electrical circuit (Kirchhoff): 3 currents
admin
matrix solve "[[1, -1, -1], [10, 5, 0], [0, 5, -20]]" "[0, 12, 0]"
mentdb
[0.8571428571428571,0.6857142857142858,0.17142857142857146]
2 equations: 2x + y = 5, x - y = 1
admin
matrix solve "[[2, 1], [1, -1]]" "[5, 1]"
mentdb
[2,1]
Mixture: 2 products at 10 % and 30 % to make 100 L at 25 %
admin
matrix solve "[[1, 1], [0.10, 0.30]]" "[100, 25]"
mentdb
[25,75]
Singular system: error
admin
matrix solve "[[1, 2], [2, 4]]" "[3, 6]"
mentdb
Sorry, an error appears (the matrix is singular: no solution or an infinity of solutions).

matrix sub <json_matrix> <json_matrix2>


Description

Subtract two matrices of the same size

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
json_matrix2: A matrix: JSON array of rows - String - required

Examples (4)
admin
matrix sub "[[1, 2], [3, 4]]" "[[5, 6], [7, 8]]"
mentdb
[[-4,-4],[-4,-4]]
A - A = 0
admin
matrix sub "[[1, 2], [3, 4]]" "[[1, 2], [3, 4]]"
mentdb
[[0,0],[0,0]]
Difference with the identity
admin
matrix sub "[[2, 1], [1, 2]]" (matrix identity 2)
mentdb
[[1,1],[1,1]]
Different sizes: error
admin
matrix sub "[[1, 2]]" "[[1, 2], [3, 4]]"
mentdb
Sorry, an error appears (the matrices must have the same size (1x2 and 2x2)).

matrix trace <json_matrix>


Description

Get the trace (sum of the diagonal) of a square matrix

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix trace "[[1, 2], [3, 4]]"
mentdb
5
3 x 3
admin
matrix trace "[[2, 0, 0], [0, 3, 4], [0, 4, 9]]"
mentdb
14
Trace of the identity = n
admin
matrix trace (matrix identity 5)
mentdb
5
Trace = sum of the eigenvalues
admin
matrix trace "[[2, -1], [-1, 2]]"
mentdb
4

matrix transpose <json_matrix>


Description

Get the transpose of a matrix

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix transpose "[[1, 2, 3], [4, 5, 6]]"
mentdb
[[1,4],[2,5],[3,6]]
Column vector to row
admin
matrix transpose "[[1], [2], [3]]"
mentdb
[[1,2,3]]
Symmetric matrix: unchanged
admin
matrix transpose "[[1, 2], [2, 3]]"
mentdb
[[1,2],[2,3]]
Row to column
admin
matrix transpose "[[1, 2, 3]]"
mentdb
[[1],[2],[3]]

matrix zeros <rows> <cols>


Description

Create a matrix filled with 0

Parameters

rows: The number of rows - Number - required
cols: The number of columns - Number - required

Examples (4)
admin
matrix zeros 2 3
mentdb
[[0,0,0],[0,0,0]]
1 x 4
admin
matrix zeros 1 4
mentdb
[[0,0,0,0]]
Square 3 x 3
admin
matrix zeros 3 3
mentdb
[[0,0,0],[0,0,0],[0,0,0]]
Column
admin
matrix zeros 3 1
mentdb
[[0],[0],[0]]

matrix cholesky <json_matrix>


Description

Get the Cholesky decomposition A = L.Lt of a symmetric positive definite matrix.
Returns {L}.

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (5)
admin
matrix cholesky "[[4, 1], [1, 3]]"
mentdb
{"L": [[2,0],[0.5,1.6583123951777]]}
3 x 3 symmetric positive
admin
matrix cholesky "[[4, 12, -16], [12, 37, -43], [-16, -43, 98]]"
mentdb
{"L": [[2,0,0],[6,1,0],[-8,5,3]]}
Identity
admin
matrix cholesky (matrix identity 2)
mentdb
{"L": [[1,0],[0,1]]}
Covariance matrix
admin
matrix cholesky "[[2, 0.6], [0.6, 1]]"
mentdb
{"L": [[1.4142135623730951,0],[0.42426406871192845,0.9055385138137417]]}
Not positive definite: error
admin
matrix cholesky "[[1, 2], [2, 1]]"
mentdb
Sorry, an error appears (the matrix is not positive definite).

matrix cond <json_matrix>


Description

Get the condition number (2-norm: largest / smallest singular value). Infinity for a singular matrix.

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix cond "[[1, 2], [3, 4]]"
mentdb
14.93303437365927
Ill-conditioned matrix (Hilbert 3 x 3)
admin
matrix cond "[[1, 0.5, 0.3333333333333333], [0.5, 0.3333333333333333, 0.25], [0.3333333333333333, 0.25, 0.2]]"
mentdb
524.0567775860604
Identity: 1
admin
matrix cond (matrix identity 3)
mentdb
1
Almost singular: very large
admin
matrix cond "[[1, 1], [1, 1.0001]]"
mentdb
40002.00007491188

matrix eigen <json_matrix>


Description

Get the eigenvalues and the eigenvectors of a square matrix.
Returns {values, vectors}: values sorted by decreasing real part; vectors = one unit vector per row (in the order of the values), its largest component positive.
When some eigenvalues are complex, they are given in the format a+bi and vectors is null.

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (6)
admin
matrix eigen "[[2, 0, 0], [0, 3, 4], [0, 4, 9]]"
mentdb
{"values": [11,2,1], "vectors": [[0,0.4472135954999579,0.8944271909999159],[1,0,0],[0,0.8944271909999159,-0.4472135954999579]]}
Rotation: complex eigenvalues
admin
matrix eigen "[[0, -1], [1, 0]]"
mentdb
{"values": ["i","-i"], "vectors": null}
Symmetric 2 x 2: normal modes of two coupled oscillators
admin
matrix eigen "[[2, -1], [-1, 2]]"
mentdb
{"values": [3,1], "vectors": [[0.7071067811865476,-0.7071067811865476],[0.7071067811865476,0.7071067811865476]]}
Diagonal matrix: the values of the diagonal
admin
matrix eigen "[[3, 0], [0, 5]]"
mentdb
{"values": [5,3], "vectors": [[0,1],[1,0]]}
Markov chain: stationary state (eigenvalue 1)
admin
matrix eigen "[[0.9, 0.5], [0.1, 0.5]]"
mentdb
{"values": [1,0.4], "vectors": [[0.9805806756909202,0.19611613513818404],[0.7071067811865476,-0.7071067811865476]]}
Inertia tensor
admin
matrix eigen "[[2, -1, 0], [-1, 2, -1], [0, -1, 2]]"
mentdb
{"values": [3.414213562373095,2,0.5857864376269051], "vectors": [[-0.5,0.7071067811865474,-0.5],[0.7071067811865477,0,-0.7071067811865474],[0.5,0.7071067811865475,0.5]]}

matrix lu <json_matrix>


Description

Get the LU decomposition with partial pivoting: P.A = L.U (error if the matrix is singular).
Returns {L, U, P}.

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix lu "[[1, 2], [3, 4]]"
mentdb
{"L": [[1,0],[0.3333333333333333,1]], "U": [[3,4],[0,0.6666666666666667]], "P": [[0,1],[1,0]]}
3 x 3
admin
matrix lu "[[2, 1, 1], [4, -6, 0], [-2, 7, 2]]"
mentdb
{"L": [[1,0,0],[0.5,1,0],[-0.5,1,1]], "U": [[4,-6,0],[0,4,1],[0,0,1]], "P": [[0,1,0],[1,0,0],[0,0,1]]}
Identity
admin
matrix lu (matrix identity 2)
mentdb
{"L": [[1,0],[0,1]], "U": [[1,0],[0,1]], "P": [[1,0],[0,1]]}
Singular matrix: error
admin
matrix lu "[[1, 2], [2, 4]]"
mentdb
Sorry, an error appears (the matrix is singular: no LU decomposition).

matrix norm <json_matrix>


Description

Get the 2-norm (spectral norm: largest singular value)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix norm "[[1, 2], [3, 4]]"
mentdb
5.464985704219043
Column 1-norm of 3 x 3
admin
matrix norm "[[1, -2, 3], [0, 4, -1], [2, 0, 1]]"
mentdb
5.229409617400718
Identity: 1
admin
matrix norm (matrix identity 3)
mentdb
1
Diagonal matrix
admin
matrix norm "[[3, 0], [0, -5]]"
mentdb
5

matrix norm_frobenius <json_matrix>


Description

Get the Frobenius norm (square root of the sum of the squares)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix norm_frobenius "[[1, 2], [3, 4]]"
mentdb
5.477225575051661
Identity 3 x 3: sqrt(3)
admin
matrix norm_frobenius (matrix identity 3)
mentdb
1.7320508075688772
Diagonal matrix
admin
matrix norm_frobenius "[[3, 0], [0, 4]]"
mentdb
5
Distance between two matrices
admin
matrix norm_frobenius (matrix sub "[[1, 2], [3, 4]]" "[[1, 2], [3, 5]]")
mentdb
1

matrix pinv <json_matrix>


Description

Get the Moore-Penrose pseudo-inverse (any size, singular matrices included)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix pinv "[[1, 2], [2, 4]]"
mentdb
[[0.04,0.08],[0.08,0.16]]
Least squares: line through 3 points (pseudo-inverse times y)
admin
matrix mul (matrix pinv "[[1, 0], [1, 1], [1, 2]]") "[1, 2, 2]"
mentdb
[1.1666666666666665,0.5]
Invertible matrix: the inverse
admin
matrix pinv "[[1, 2], [3, 4]]"
mentdb
[[-2,1],[1.5,-0.5]]
Rectangular matrix
admin
matrix pinv "[[1, 2, 3]]"
mentdb
[[0.07142857142857141],[0.14285714285714288],[0.2142857142857143]]

matrix pow <json_matrix> <n>


Description

Get A^n (n integer; negative n: power of the inverse)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required
n: An integer - Number - required

Examples (6)
admin
matrix pow "[[1, 2], [3, 4]]" 3
mentdb
[[37,54],[81,118]]
admin
matrix pow "[[1, 2], [3, 4]]" -1
mentdb
[[-2,1],[1.5,-0.5]]
Fibonacci numbers: [[1, 1], [1, 0]]^10
admin
matrix pow "[[1, 1], [1, 0]]" 10
mentdb
[[89,55],[55,34]]
Power 0: identity
admin
matrix pow "[[1, 2], [3, 4]]" 0
mentdb
[[1,0],[0,1]]
Markov chain after 10 steps
admin
matrix pow "[[0.9, 0.1], [0.5, 0.5]]" 10
mentdb
[[0.8333508096,0.1666491904],[0.833245952,0.166754048]]
Not square: error
admin
matrix pow "[[1, 2, 3]]" 2
mentdb
Sorry, an error appears (the matrix must be square (1x3)).

matrix qr <json_matrix>


Description

Get the QR decomposition A = Q.R (Q orthogonal, R upper triangular, Householder method).
Returns {Q, R}.

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (3)
admin
matrix qr "[[1, 2], [3, 4]]"
mentdb
{"Q": [[-0.3162277660168382,0.9486832980505142],[-0.9486832980505138,-0.3162277660168382]], "R": [[-3.1622776601683795,-4.427188724235732],[0,0.632455532033676]]}
3 x 2
admin
matrix qr "[[1, 1], [1, 2], [1, 3]]"
mentdb
{"Q": [[-0.577350269189626,0.7071067811865476,0.4082482904638629],[-0.5773502691896258,0,-0.816496580927726],[-0.5773502691896258,-0.7071067811865475,0.4082482904638631]], "R": [[-1.7320508075688772,-3.4641016151377544],[0,-1.4142135623730951],[0,0]]}
Square 3 x 3
admin
matrix qr "[[12, -51, 4], [6, 167, -68], [-4, 24, -41]]"
mentdb
{"Q": [[-0.857142857142857,0.3942857142857143,-0.3314285714285714],[-0.42857142857142855,-0.9028571428571428,0.03428571428571431],[0.2857142857142857,-0.17142857142857143,-0.9428571428571428]], "R": [[-14,-21,14],[0,-175,70],[0,0,35]]}

matrix rank <json_matrix>


Description

Get the rank (number of non negligible singular values)

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix rank "[[1, 2, 3], [2, 4, 6], [1, 0, 1]]"
mentdb
2
Full rank
admin
matrix rank "[[1, 0], [0, 1]]"
mentdb
2
Zero matrix: 0
admin
matrix rank (matrix zeros 2 2)
mentdb
0
Rectangular
admin
matrix rank "[[1, 2, 3, 4], [2, 4, 6, 8]]"
mentdb
1

matrix rref <json_matrix>


Description

Get the reduced row echelon form (Gauss-Jordan with partial pivoting). Solving a system: rref of the augmented matrix [A|b].

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix rref "[[1, 2, -1, -4], [2, 3, -1, -11], [-2, 0, -3, 22]]"
mentdb
[[1,0,0,-8],[0,1,0,1],[0,0,1,-2]]
Reduced row echelon form of a 2 x 3 system
admin
matrix rref "[[1, 2, 5], [3, 4, 6]]"
mentdb
[[1,0,-4],[0,1,4.5]]
Singular system: a row of zeros
admin
matrix rref "[[1, 2, 3], [2, 4, 6]]"
mentdb
[[1,2,3],[0,0,0]]
Inverse with the augmented matrix [A | I]
admin
matrix rref "[[2, 1, 1, 0], [1, 1, 0, 1]]"
mentdb
[[1,0,1,-1],[0,1,-1,2]]

matrix svd <json_matrix>


Description

Get the singular value decomposition A = U.diag(S).Vt (compact form).
Returns {U, S, V}: S = the singular values in decreasing order.

Parameters

json_matrix: A matrix: JSON array of rows, ex: [[1, 2], [3, 4]] - String - required

Examples (4)
admin
matrix svd "[[1, 2], [3, 4]]"
mentdb
{"U": [[0.4045535848337569,0.9145142956773045],[0.9145142956773045,-0.4045535848337569]], "S": [5.464985704219043,0.3659661906262574], "V": [[0.5760484367663208,-0.8174155604703632],[0.8174155604703632,0.5760484367663208]]}
Singular values of a 3 x 2 matrix
admin
matrix svd "[[3, 2], [2, 3], [2, -2]]"
mentdb
{"U": [[0.7071067811865475,-0.23570226039551587],[0.7071067811865477,0.235702260395516],[0,-0.9428090415820634]], "S": [5,3], "V": [[0.7071067811865475,-0.7071067811865475],[0.7071067811865475,0.7071067811865475]]}
Diagonal matrix
admin
matrix svd "[[3, 0], [0, 2]]"
mentdb
{"U": [[-1,0],[0,1]], "S": [3,2], "V": [[-1,0],[0,1]]}
Matrix of rank 1
admin
matrix svd "[[1, 2], [2, 4]]"
mentdb
{"U": [[-0.44721359549995787,-0.894427190999916],[-0.8944271909999159,0.44721359549995787]], "S": [5,0], "V": [[-0.447213595499958,-0.894427190999916],[-0.894427190999916,0.447213595499958]]}

vector angle <json_vector> <json_vector2>


Description

Get the angle between two vectors (radians, in [0, pi])

Parameters

json_vector: A vector: JSON array of numbers, ex: [1, 2, 3] - String - required
json_vector2: A vector: JSON array of numbers - String - required

Examples (5)
admin
vector angle "[1, 0, 0]" "[1, 1, 0]"
mentdb
0.7853981633974483
Orthogonal vectors: pi/2
admin
vector angle "[1, 2]" "[-2, 1]"
mentdb
1.5707963267948966
Perpendicular vectors: pi/2
admin
vector angle "[1, 0]" "[0, 1]"
mentdb
1.5707963267948966
Opposite vectors: pi
admin
vector angle "[1, 1]" "[-2, -2]"
mentdb
3.141592653589793
In degrees
admin
math rad_to_deg (vector angle "[1, 0, 0]" "[1, 1, 1]")
mentdb
54.735610317245346

vector cross <json_vector> <json_vector2>


Description

Get the cross product of two vectors of size 3

Parameters

json_vector: A vector: JSON array of numbers, ex: [1, 2, 3] - String - required
json_vector2: A vector: JSON array of numbers - String - required

Examples (5)
admin
vector cross "[1, 0, 0]" "[0, 1, 0]"
mentdb
[0,0,1]
Torque r x F
admin
vector cross "[0.5, 0, 0]" "[0, 10, 0]"
mentdb
[0,0,5]
Parallel vectors: zero vector
admin
vector cross "[1, 2, 3]" "[2, 4, 6]"
mentdb
[0,0,0]
Area of the triangle (0,0,0), (1,0,0), (0,1,1): half of the norm
admin
-> "[n]" (vector norm (vector cross "[1, 0, 0]" "[0, 1, 1]")); math calc "[n]/2"
mentdb
0.7071067811865476
Not in 3 dimensions: error
admin
vector cross "[1, 2]" "[3, 4]"
mentdb
Sorry, an error appears (the cross product needs two vectors of size 3 (2 and 2)).

vector dot <json_vector> <json_vector2>


Description

Get the dot product of two vectors

Parameters

json_vector: A vector: JSON array of numbers, ex: [1, 2, 3] - String - required
json_vector2: A vector: JSON array of numbers - String - required

Examples (4)
admin
vector dot "[1, 2, 3]" "[4, 5, 6]"
mentdb
32
Work of a force W = F . d
admin
vector dot "[10, 0, 5]" "[3, 4, 0]"
mentdb
30
Perpendicular: 0
admin
vector dot "[1, 2]" "[-2, 1]"
mentdb
0
Different sizes: error
admin
vector dot "[1, 2]" "[1, 2, 3]"
mentdb
Sorry, an error appears (the vectors must have the same size (2 and 3)).

vector norm <json_vector>


Description

Get the Euclidean norm of a vector

Parameters

json_vector: A vector: JSON array of numbers, ex: [1, 2, 3] - String - required

Examples (4)
admin
vector norm "[3, 4]"
mentdb
5
3D vector
admin
vector norm "[1, 2, 2]"
mentdb
3
4 dimensions
admin
vector norm "[1, 1, 1, 1]"
mentdb
2
Speed from the components (m/s)
admin
vector norm "[3.2, -1.5, 0.8]"
mentdb
3.6235341863986883

vector unit <json_vector>


Description

Get the unit vector (same direction, norm 1)

Parameters

json_vector: A vector: JSON array of numbers, ex: [1, 2, 3] - String - required

Examples (4)
admin
vector unit "[3, 4]"
mentdb
[0.6,0.8]
3D unit vector
admin
vector unit "[1, 2, 2]"
mentdb
[0.3333333333333333,0.6666666666666666,0.6666666666666666]
Already of norm 1
admin
vector unit "[0, 1, 0]"
mentdb
[0,1,0]
Direction of a force
admin
vector unit "[10, -10, 5]"
mentdb
[0.6666666666666666,-0.6666666666666666,0.3333333333333333]

vector add <json_vector> <json_vector2>


Description

Add two vectors

Parameters

json_vector: A vector: JSON array of numbers - String - required
json_vector2: A vector: JSON array of numbers - String - required

Examples (4)
admin
vector add "[1, 2, 3]" "[4, 5, 6]"
mentdb
[5,7,9]
Sum of two forces
admin
vector add "[3, 0]" "[0, 4]"
mentdb
[3,4]
Sum of forces
admin
vector add "[10, 0, 0]" "[0, -5, 2]"
mentdb
[10,-5,2]
Different sizes: error
admin
vector add "[1, 2]" "[1, 2, 3]"
mentdb
Sorry, an error appears (the vectors must have the same size (2 and 3)).

vector scale <json_vector> <k>


Description

Multiply a vector by a number

Parameters

json_vector: A vector: JSON array of numbers - String - required
k: The number - Number - required

Examples (4)
admin
vector scale "[1, 2, 3]" 2.5
mentdb
[2.5,5,7.5]
Opposite vector
admin
vector scale "[1, -2, 3]" -1
mentdb
[-1,2,-3]
By 0
admin
vector scale "[1, 2, 3]" 0
mentdb
[0,0,0]
Velocity x time = displacement
admin
vector scale "[2.5, 0, -1]" 4
mentdb
[10,0,-4]

vector sub <json_vector> <json_vector2>


Description

Subtract two vectors

Parameters

json_vector: A vector: JSON array of numbers - String - required
json_vector2: A vector: JSON array of numbers - String - required

Examples (4)
admin
vector sub "[1, 2, 3]" "[4, 5, 6]"
mentdb
[-3,-3,-3]
Displacement between two points
admin
vector sub "[5, 7, 2]" "[1, 2, 2]"
mentdb
[4,5,0]
Vector from point A to point B: B - A
admin
vector sub "[4, 6, 1]" "[1, 2, 1]"
mentdb
[3,4,0]
Same vector: zero
admin
vector sub "[1, 2]" "[1, 2]"
mentdb
[0,0]
start: 2026-10-29end: 2026-10-29v_start: 421v_end: