CODESCRIPT

Matrices

51 entries. What each one takes, what it returns, and a working example.

matrixAdd(a, b)

A new matrix with the cells at each position added together.

a
matrix
The first matrix.
b
matrix
The second matrix; must have the same size as a.
NOTE

The two matrices are added cell by cell. The result is a new matrix; the inputs are unchanged.

CODESCRIPT
a = matrixNew(2, 2, 1)
b = matrixNew(2, 2, 2)
s = matrixAdd(a, b)
plot(matrixGet(s, 0, 0))

1+2 = 3 (every cell).

matrixAddCol(m, i?, dizi?)

Returns nothing (na); it grows the matrix by one column in place.

matris
matrix
The matrix to add a column to.
i
number
The insert position (optional); appended at the end if omitted. Clamped into the 0..cols range if out of range.
dizi
array
An array of the column values (optional); padded with 0 if shorter than the row count.
NOTE

Inserts the array as a column at the given position and increases the column count. If the matrix is empty (0 rows), the added column's length sets the row count.

CODESCRIPT
m = matrixNew(2, 1, 1)
matrixAddCol(m, 1, arrayFrom(7, 8))
plot(matrixGet(m, 0, 1))

First cell of the appended column is 7.

matrixAddRow(m, i?, dizi?)

Returns nothing (na); it grows the matrix by one row in place.

matris
matrix
The matrix to add a row to.
i
number
The insert position (optional); appended at the end if omitted. Clamped into the 0..rows range if out of range.
dizi
array
An array of the row values (optional); padded with 0 if shorter than the column count, truncated if longer.
NOTE

Inserts the array as a row at the given position and increases the row count. If the matrix is empty (0 columns), the first added row's length sets the column count.

CODESCRIPT
m = matrixNew(1, 2, 1)
matrixAddRow(m, 1, arrayFrom(7, 8))
plot(matrixGet(m, 1, 0))

First cell of the appended row is 7.

matrixAvg(matris)

The arithmetic mean of all cells; na if the matrix is empty or not a matrix.

matris
matrix
The matrix to average.
NOTE

Divides the sum by the cell count. Returns na (not 0) on an empty matrix; guard the result with na().

CODESCRIPT
m = matrixNew(2, 2, 4)
plot(matrixAvg(m))

All cells 4 → mean 4.

matrixCol(matris, j)

An array holding the values of column j; an empty array if the index is out of range.

matris
matrix
The matrix to take a column from.
j
number
Column index; 0 is the first column.
NOTE

Collects the column top to bottom into an array. The returned array is a copy; it does not affect the matrix.

CODESCRIPT
m = matrixNew(3, 2, 5)
c = matrixCol(m, 1)
plot(arraySize(c))

Column 1 has 3 elements.

matrixCols(matris)

The number of columns in the matrix; 0 if it is not a matrix.

matris
matrix
The matrix to measure.
NOTE

Used as the loop bound over columns. matrixColumns is a second name for the same thing.

CODESCRIPT
m = matrixNew(3, 2, 0)
plot(matrixCols(m))

2 columns.

matrixColumns(m)

The number of columns in the matrix; 0 if it is not a matrix.

matris
matrix
The matrix to measure.
NOTE

Returns exactly the same result as matrixCols — an alternative name provided for readability.

CODESCRIPT
m = matrixNew(3, 4, 0)
plot(matrixColumns(m))

4 columns.

matrixConcat(m1, m2)

A new matrix with m2's rows appended below m1's rows.

m1
matrix
The top matrix.
m2
matrix
The matrix to append below; its column count must match m1.
NOTE

Performs a vertical stack (appends rows below). The result is a new matrix; the inputs are unchanged.

CODESCRIPT
a = matrixNew(1, 2, 1)
b = matrixNew(2, 2, 2)
c = matrixConcat(a, b)
plot(matrixRows(c))

1 row + 2 rows → 3 rows.

matrixCopy(matris)

An independent (deep) copy of the source; an empty 0×0 matrix if it is not a matrix.

matris
matrix
The matrix to copy.
NOTE

The copy is fully separate from the original; changing one does not affect the other. Used to experiment on a matrix without corrupting it.

CODESCRIPT
m = matrixNew(2, 2, 1)
c = matrixCopy(m)
matrixSet(c, 0, 0, 9)
plot(matrixGet(m, 0, 0))

Even after the copy changes, the original [0,0] stays 1.

matrixDet(matris)

The determinant of the matrix (a single number); na if it is not square or not a matrix. Returns 0 for a singular (non-invertible) matrix.

matris
matrix
The square matrix to take the determinant of.
NOTE

Computed by elimination with partial pivoting. A determinant of 0 means the matrix has no inverse (its rows/columns are dependent).

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 2)
matrixSet(m, 1, 1, 3)
plot(matrixDet(m))

Diagonal 2,3 → determinant 6.

matrixDiff(m1, m2)

A new matrix with m2 subtracted from m1.

m1
matrix
The matrix to subtract from.
m2
matrix
The matrix to subtract (same size) or a single number to subtract from every cell.
NOTE

If the second argument is a matrix, subtraction is done cell by cell; if it is a single number, that number is subtracted from all cells. The result is a new matrix.

CODESCRIPT
a = matrixNew(2, 2, 5)
b = matrixNew(2, 2, 2)
d = matrixDiff(a, b)
plot(matrixGet(d, 0, 0))

5-2 = 3 (every cell).

matrixEigenvalues(m)

An array of eigenvalues sorted from largest to smallest; an empty array if it is not square or is empty.

matris
matrix
The square (symmetric) matrix to take eigenvalues of.
NOTE

Computed by the Jacobi method for symmetric matrices. Eigenvalues give the matrix's diagonal magnitudes (its scale along the principal axes).

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 2)
matrixSet(m, 1, 1, 3)
ev = matrixEigenvalues(m)
plot(arrayGet(ev, 0))

Diagonal 2,3 → largest eigenvalue 3.

matrixEigenvectors(m)

A new matrix whose columns are the eigenvectors; an empty matrix if it is not square or is empty.

matris
matrix
The square (symmetric) matrix to take eigenvectors of.
NOTE

Computed by the Jacobi method for symmetric matrices; each column of the result matrix is an eigenvector, matching the order of matrixEigenvalues.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 2)
matrixSet(m, 1, 1, 3)
v = matrixEigenvectors(m)
plot(matrixRows(v))

2×2 symmetric → eigenvector matrix has 2 rows.

matrixElementsCount(m)

The total cell count (rows × columns); 0 if it is not a matrix.

matris
matrix
The matrix to count.
NOTE

Useful to check whether a matrix is non-empty before feeding statistics functions (matrixAvg, matrixMedian).

CODESCRIPT
m = matrixNew(2, 3, 0)
plot(matrixElementsCount(m))

2×3 = 6 cells.

matrixFill(matris, değer)

Returns nothing (na); it sets every cell of the matrix to the value in place.

matris
matrix
The matrix to fill.
değer
number
The value written to every cell; 0 if non-numeric.
NOTE

Does not change the size, it just overwrites the contents with a single value. A quick way to reset a matrix before reusing it.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixFill(m, 3)
plot(matrixSum(m))

All four cells become 3 → sum 12.

matrixGet(matris, i, j)

The cell value at row i, column j; returns na if the index is out of range (no error).

matris
matrix
The matrix to read from.
i
number
Row index; 0 is the first row.
j
number
Column index; 0 is the first column.
NOTE

Rows and columns start at 0. An out-of-range index does not crash, it yields na; you can check the result with na().

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 1, 9)
plot(matrixGet(m, 0, 1))

Reads the 9 written at row 0, column 1.

matrixInv(matris)

The inverse of the matrix (a new matrix); na if it is not square or is singular (has no inverse).

matris
matrix
The square matrix to invert.
NOTE

Computed by Gauss-Jordan elimination. Multiplying by the inverse yields the identity. A matrix with determinant 0 has no inverse; na is returned then.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 4)
matrixSet(m, 1, 1, 4)
inv = matrixInv(m)
plot(matrixGet(inv, 0, 0))

Diagonal 4 → inverse diagonal 0.25.

matrixIsAntidiagonal(m)

true if it is square and every cell outside the anti-diagonal (i+j = n-1) is 0; otherwise false.

matris
matrix
The matrix to check.
NOTE

The anti-diagonal runs from top-right to bottom-left; this check verifies that only that diagonal may be filled.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 1, 3)
matrixSet(m, 1, 0, 4)
plot(matrixIsAntidiagonal(m) ? 1 : 0)

Only the anti-diagonal is filled → 1 (yes).

matrixIsAntisymmetric(m)

true if it is square and each cell equals the negative of its mirror (m[i][j] = -m[j][i]); otherwise false.

matris
matrix
The matrix to check.
NOTE

In an antisymmetric matrix the diagonal is necessarily 0 (since m[i][i] = -m[i][i] holds only for 0).

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 1, 3)
matrixSet(m, 1, 0, -3)
plot(matrixIsAntisymmetric(m) ? 1 : 0)

Diagonal 0, mirrors opposite-signed → 1.

matrixIsBinary(m)

true if every cell is only 0 or 1, otherwise false.

matris
matrix
The matrix to check.
NOTE

Used to validate structures that should contain only 0-1, such as an adjacency matrix.

CODESCRIPT
m = matrixNew(2, 2, 1)
plot(matrixIsBinary(m) ? 1 : 0)

All cells 1 → 1 (yes).

matrixIsDiagonal(m)

true if it is square and every off-diagonal cell is 0; otherwise false.

matris
matrix
The matrix to check.
NOTE

The diagonal values may be any number; the condition is only that the off-diagonal is 0.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 5)
matrixSet(m, 1, 1, 7)
plot(matrixIsDiagonal(m) ? 1 : 0)

Only the diagonal is filled → 1 (yes).

matrixIsIdentity(m)

true if it is square with a diagonal of 1 and off-diagonal cells of 0; otherwise false.

matris
matrix
The matrix to check.
NOTE

The identity is the neutral element in multiplication (m × identity = m). This check tells whether a matrix is the identity.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 1, 1, 1)
plot(matrixIsIdentity(m) ? 1 : 0)

Diagonal 1, rest 0 → 1 (yes).

matrixIsSquare(m)

true if the row count equals the column count, otherwise false.

matris
matrix
The matrix to check.
NOTE

Used as a guard before functions that require a square matrix (determinant, inverse, power, trace).

CODESCRIPT
m = matrixNew(3, 3, 0)
plot(matrixIsSquare(m) ? 1 : 0)

3×3 is square → 1 (yes).

matrixIsStochastic(m)

true if every row sums to 1 (within a small rounding tolerance); otherwise false.

matris
matrix
The matrix to check.
NOTE

This is a row-stochastic check; being square is not required, only that each row sums to 1. Used to validate transition (Markov) matrices.

CODESCRIPT
m = matrixNew(2, 2, 0.5)
plot(matrixIsStochastic(m) ? 1 : 0)

Each row 0.5+0.5 = 1 → 1 (yes).

matrixIsSymmetric(m)

true if it is square and equals its transpose (m[i][j] = m[j][i]); otherwise false.

matris
matrix
The matrix to check.
NOTE

A symmetric matrix is a mirror across the diagonal. Covariance and correlation matrices are symmetric; the eigenvalue functions are designed for such matrices.

CODESCRIPT
m = matrixNew(2, 2, 5)
plot(matrixIsSymmetric(m) ? 1 : 0)

All cells equal → symmetric → 1.

matrixIsTriangular(m)

true if it is square and either lower- or upper-triangular (one side of the diagonal is all 0); otherwise false.

matris
matrix
The matrix to check.
NOTE

In an upper-triangular matrix the area below the diagonal is zero, in a lower-triangular one the area above. Either case qualifies as triangular.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 0, 1, 2)
matrixSet(m, 1, 1, 3)
plot(matrixIsTriangular(m) ? 1 : 0)

Below-diagonal is 0 → upper-triangular → 1.

matrixIsZero(m)

true if every cell is 0, false if even one is non-zero.

matris
matrix
The matrix to check.
NOTE

Can be used to check whether a computation wrote any value into the matrix.

CODESCRIPT
m = matrixNew(2, 2, 0)
plot(matrixIsZero(m) ? 1 : 0)

All cells 0 → 1 (yes).

matrixKron(m1, m2)

The Kronecker product of the two matrices; a new matrix of size (m1.rows×m2.rows) × (m1.cols×m2.cols).

m1
matrix
The left matrix.
m2
matrix
The right matrix.
NOTE

Each cell of m1 is multiplied by all of m2 and placed block by block. The result grows to the product of both sizes.

CODESCRIPT
a = matrixNew(2, 2, 1)
b = matrixNew(2, 2, 1)
k = matrixKron(a, b)
plot(matrixRows(k))

2×2 ⊗ 2×2 → 4×4, row count 4.

matrixMax(m)

The largest value across all cells; na if the matrix is empty or not a matrix.

matris
matrix
The matrix to find the maximum of.
NOTE

Compares all cells without distinguishing rows or columns.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 1, 1, 8)
plot(matrixMax(m))

One cell is 8 → maximum 8.

matrixMedian(m)

The median of all cells; if the cell count is even, the mean of the two middle values. na if empty.

matris
matrix
The matrix to take the median of.
NOTE

All cells are sorted and the middle value is taken. The median is less sensitive to outliers than the mean.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 0, 1, 2)
matrixSet(m, 1, 0, 3)
matrixSet(m, 1, 1, 4)
plot(matrixMedian(m))

1,2,3,4 → mean of the two middle values is 2.5.

matrixMin(m)

The smallest value across all cells; na if the matrix is empty or not a matrix.

matris
matrix
The matrix to find the minimum of.
NOTE

Compares all cells without distinguishing rows or columns.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, -5)
plot(matrixMin(m))

One cell is -5 → minimum -5.

matrixMode(m)

The most frequently repeated cell value; the smallest one if several share the top frequency. na if empty.

matris
matrix
The matrix to find the mode of.
NOTE

When several values share the highest frequency, the smallest value is chosen (a stable, deterministic result).

CODESCRIPT
m = matrixNew(2, 2, 1)
matrixSet(m, 0, 0, 5)
plot(matrixMode(m))

Three 1s and one 5 → mode 1.

matrixMult(a, b)

The a×b matrix product; a new matrix of size a.rows × b.cols.

a
matrix
The left matrix (rows×inner).
b
matrix
The right matrix; its row count must equal a's column count.
NOTE

This is true matrix multiplication (not element-wise): result[i][j] is the dot product of a's row i with b's column j.

CODESCRIPT
a = matrixNew(2, 2, 0)
matrixSet(a, 0, 0, 1)
matrixSet(a, 1, 1, 1)
b = matrixNew(2, 2, 5)
p = matrixMult(a, b)
plot(matrixGet(p, 0, 0))

Identity × b = b → [0,0] = 5.

matrixNew(satır, sütun, başlangıç?)

A new satır×sütun matrix with every cell set to the initial value.

satır
number
The row count of the matrix to build; a negative value is clamped to 0.
sütun
number
The column count; a negative value is clamped to 0.
başlangıç
number
Initial value for every cell (optional). If omitted or non-numeric, 0 is used.
NOTE

A matrix is a two-dimensional grid of numbers made of rows and columns; every other matrix function expects an object built this way.

CODESCRIPT
m = matrixNew(2, 3, 0)
plot(matrixElementsCount(m))

A 2×3 matrix with 6 cells.

CODESCRIPT
m = matrixNew(2, 2, 5)
plot(matrixSum(m))

All four cells are 5 → sum 20.

matrixPinv(m)

The pseudo-inverse of the matrix (the Moore-Penrose left inverse); na if (mᵀm) cannot be inverted.

matris
matrix
The matrix to pseudo-invert.
NOTE

Computed as (mᵀm)⁻¹mᵀ; it gives the least-squares solution for non-square or non-invertible matrices. For a square invertible matrix the result equals the ordinary inverse.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 2)
matrixSet(m, 1, 1, 4)
p = matrixPinv(m)
plot(matrixGet(p, 0, 0))

Diagonal 2 → pseudo-inverse diagonal 0.5.

matrixPow(m, n)

The matrix raised to the n-th power (matrix×matrix multiplied n times); a new matrix.

matris
matrix
The square matrix to raise to a power.
n
number
The exponent (integer); treated as 0 if negative. 0 yields the identity matrix.
NOTE

Multiplies the matrix by itself n times (not an ordinary numeric power). At n=0 the identity, at n=1 the matrix itself is returned.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 0, 0, 2)
matrixSet(m, 1, 1, 3)
p = matrixPow(m, 2)
plot(matrixGet(p, 0, 0))

Diagonal 2 → squared 4.

matrixRank(m)

The rank of the matrix (the number of independent rows/columns); 0 if it is not a matrix.

matris
matrix
The matrix to compute the rank of.
NOTE

Computed by elimination. If the rank is less than the row or column count, the matrix has dependency (redundancy) and no inverse.

CODESCRIPT
m = matrixNew(2, 2, 5)
plot(matrixRank(m))

All rows identical → rank 1.

matrixRemoveCol(m, i)

An array of the removed column's values; an empty array if the index is out of range.

matris
matrix
The matrix to remove a column from.
i
number
The column index to remove.
NOTE

Deletes the column from the matrix (the column count drops by one) and returns that column as an array. Modifies in place.

CODESCRIPT
m = matrixNew(2, 3, 0)
matrixSet(m, 0, 1, 5)
c = matrixRemoveCol(m, 1)
plot(arrayGet(c, 0))

First value of the removed column 1 is 5.

matrixRemoveRow(m, i)

An array of the removed row's values; an empty array if the index is out of range.

matris
matrix
The matrix to remove a row from.
i
number
The row index to remove.
NOTE

Deletes the row from the matrix (the row count drops by one) and returns that row as an array. Modifies in place.

CODESCRIPT
m = matrixNew(3, 2, 0)
matrixSet(m, 1, 0, 9)
r = matrixRemoveRow(m, 1)
plot(arrayGet(r, 0))

First value of the removed row 1 is 9.

matrixReshape(m, satır, sütun)

A new matrix that places the same cells into the new rows×columns layout.

matris
matrix
The matrix to reshape.
satır
number
The new row count.
sütun
number
The new column count.
NOTE

Cells are read row-major and poured into the new shape. If the new size is larger, missing cells become 0; if smaller, extra cells are dropped. Does not change the source.

CODESCRIPT
m = matrixNew(2, 3, 4)
r = matrixReshape(m, 3, 2)
plot(matrixRows(r))

2×3 (6 cells) → 3×2, row count 3.

matrixReverse(m)

Returns nothing (na); it reverses the row and column order in place.

matris
matrix
The matrix to reverse.
NOTE

Reverses both the order of rows and the cells within each row; the first cell swaps with the last (a 180° rotation effect). Modifies in place.

CODESCRIPT
m = matrixNew(1, 3, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 0, 2, 3)
matrixReverse(m)
plot(matrixGet(m, 0, 0))

[1,0,3] → reversed [3,0,1], first cell 3.

matrixRow(matris, i)

An array holding a copy of row i; an empty array if the index is out of range.

matris
matrix
The matrix to take a row from.
i
number
Row index; 0 is the first row.
NOTE

The returned array is a copy; modifying it does not affect the source matrix. An empty result reads as size 0 with arraySize.

CODESCRIPT
m = matrixNew(2, 3, 4)
r = matrixRow(m, 0)
plot(arraySum(r))

Row 0 is [4,4,4] → sum 12.

matrixRows(matris)

The number of rows in the matrix; 0 if it is not a matrix.

matris
matrix
The matrix to measure.
NOTE

Used to know the bound before looping over rows. For the column count use matrixCols.

CODESCRIPT
m = matrixNew(3, 2, 0)
plot(matrixRows(m))

3 rows.

matrixSet(matris, i, j, değer)

Returns nothing (na); it modifies the matrix in place.

matris
matrix
The matrix to modify.
i
number
Row index to write.
j
number
Column index to write.
değer
number
The value to store in the cell; if non-numeric, 0 is written.
NOTE

Overwrites an existing cell; it does not grow the matrix. If the index is out of range it silently does nothing. To add a new row/column use matrixAddRow/matrixAddCol.

CODESCRIPT
m = matrixNew(2, 2, 0)
matrixSet(m, 1, 1, 7)
plot(matrixGet(m, 1, 1))

The bottom-right cell is set to 7.

matrixSort(m, sütun, artan?)

Returns nothing (na); it sorts the matrix rows in place.

matris
matrix
The matrix to sort.
sütun
number
The column index to sort by.
artan
bool
true → ascending (small to large), false → descending (optional, default ascending).
NOTE

Rows are reordered as whole units by the value in the chosen column (each row stays intact internally). Does nothing if the column index is invalid.

CODESCRIPT
m = matrixNew(2, 1, 0)
matrixSet(m, 0, 0, 5)
matrixSet(m, 1, 0, 1)
matrixSort(m, 0, true)
plot(matrixGet(m, 0, 0))

Ascending sort → the smallest (1) comes first.

matrixSubmatrix(m, r1, r2, c1, c2)

A new matrix made of rows [r1, r2) and columns [c1, c2).

matris
matrix
The matrix to slice.
r1
number
The start row (inclusive).
r2
number
The end row (exclusive).
c1
number
The start column (inclusive).
c2
number
The end column (exclusive).
NOTE

The end indices are exclusive (r2 and c2 are not included). Does not change the source; returns a copy of the sliced region.

CODESCRIPT
m = matrixNew(3, 3, 0)
matrixSet(m, 1, 1, 5)
s = matrixSubmatrix(m, 1, 2, 1, 2)
plot(matrixGet(s, 0, 0))

The single middle cell (5) is taken.

matrixSum(matris)

The sum of all cells; 0 if it is not a matrix.

matris
matrix
The matrix to sum.
NOTE

Sums all values without distinguishing rows or columns. Yields 0 for an empty matrix.

CODESCRIPT
m = matrixNew(2, 2, 2.5)
plot(matrixSum(m))

Four cells of 2.5 → sum 10.

matrixSwapColumns(m, i, j)

Returns nothing (na); it swaps columns i and j in place.

matris
matrix
The matrix whose columns are swapped.
i
number
The first column index.
j
number
The second column index.
NOTE

Swaps two whole columns. Does nothing if either index is out of range.

CODESCRIPT
m = matrixNew(1, 2, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 0, 1, 2)
matrixSwapColumns(m, 0, 1)
plot(matrixGet(m, 0, 0))

Columns swapped → [0,0] is now 2.

matrixSwapRows(m, i, j)

Returns nothing (na); it swaps rows i and j in place.

matris
matrix
The matrix whose rows are swapped.
i
number
The first row index.
j
number
The second row index.
NOTE

Swaps two whole rows. Does nothing if either index is out of range.

CODESCRIPT
m = matrixNew(2, 1, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 1, 0, 2)
matrixSwapRows(m, 0, 1)
plot(matrixGet(m, 0, 0))

Rows swapped → [0,0] is now 2.

matrixTrace(matris)

The sum of the main-diagonal (i==j) cells; 0 if it is not a matrix.

matris
matrix
The matrix to take the trace of.
NOTE

For a non-square matrix it sums the diagonal up to the shorter side. The trace reduces the diagonal energy to a single number.

CODESCRIPT
m = matrixNew(3, 3, 0)
matrixSet(m, 0, 0, 1)
matrixSet(m, 1, 1, 2)
matrixSet(m, 2, 2, 3)
plot(matrixTrace(m))

Diagonal 1+2+3 = 6.

matrixTranspose(matris)

A new matrix with rows and columns swapped (of size cols×rows).

matris
matrix
The matrix to transpose.
NOTE

Does not change the source, it returns a new matrix. Cell at row i, column j becomes row j, column i in the output.

CODESCRIPT
m = matrixNew(2, 3, 0)
t = matrixTranspose(m)
plot(matrixRows(t))

2×3 → transpose is 3×2, row count 3.