Matrix & Vector functions
CalcTree supports a wide range of matrix and array functions using MathJS syntax. These functions are useful for vector operations, 2D geometry, and working with tabular data.
To create a matrix or vector, use square brackets:
[1, 2, 3] // 1D vector
[[1, 2], [3, 4]] // 2x2 matrixConstruction & Access
identity(n)
Identity matrix (n × n)
identity(3) → [[1,0,0],[0,1,0],[0,0,1]]
zeros(m, n)
Matrix of zeros
zeros(2, 3) → [[0,0,0],[0,0,0]]
ones(m, n)
Matrix of ones
ones(2, 2) → [[1,1],[1,1]]
range(start, end [, step])
Create array with range
range(1, 5) → [1,2,3,4]
size(x)
Shape of array or matrix
size([[1,2],[3,4]]) → [2,2]
row(M, i)
Return row at index i
row([[1,2],[3,4]], 1) → [3, 4]
column(M, i)
Return column at index i
column([[1,2],[3,4]], 0) → [1, 3]
count(x)
Count number of elements
count([[1,2],[3,4]]) → 4
diag(x)
Create diagonal matrix or extract diagonal
diag([1,2,3]) → [[1,0,0],[0,2,0],[0,0,3]]
Transformation & Operations
transpose(x)
Transpose matrix or vector
transpose([[1,2],[3,4]]) → [[1,3],[2,4]]
ctranspose(x)
Complex transpose + conjugate
ctranspose([[1+2i],[3-4i]]) → [[1-2i, 3+4i]]
flatten(x)
Flatten to 1D array
flatten([[1,2],[3,4]]) → [1,2,3,4]
reshape(x, sizes)
Reshape array
reshape([1,2,3,4], [2,2]) → [[1,2],[3,4]]
squeeze(x)
Remove singleton dimensions
squeeze([[1]]) → 1
resize(x, size [, default])
Resize and pad
resize([1,2], [4], 0) → [1,2,0,0]
rotate(vec, theta)
Rotate 2D vector counter-clockwise
rotate([1, 0], pi/2) → [0, 1]
getMatrixDataType(x)
Type of values in a matrix
getMatrixDataType([[1,2],[3,4]]) → "number"
Vector & Matrix Math
dot(a, b)
Dot product (vectors)
dot([2,3], [4,5]) → 23
cross(a, b)
Cross product (3D vectors)
cross([1,0,0], [0,1,0]) → [0,0,1]
norm(x [, p])
Vector or matrix norm
norm([3, 4]) → 5
det(A)
Determinant
det([[1,2],[3,4]]) → -2
inv(A)
Inverse of matrix
inv([[4,7],[2,6]])
trace(A)
Trace (sum of diagonal)
trace([[1,2],[3,4]]) → 5
sqrtm(A)
Matrix square root
sqrtm([[4,0],[0,9]]) → [[2,0],[0,3]]
expm(A)
Matrix exponential
expm([[0,1],[-1,0]])
Signal Transformations
fft(x)
Fast Fourier Transform
fft([0,1,0,0]) → complex array
ifft(x)
Inverse FFT
ifft([...]) → original signal
Sorting & Selection
sort(x)
Sort 1D array
sort([3,1,2]) → [1,2,3]
partitionSelect(x, k)
k-th order statistic in a 1D array (quickselect)
partitionSelect([3,5,1,2], 1) → 2
Matrix Decomposition (Advanced)
These are available in MathJS, but may have limited or no support in CalcTree yet.
eigs(A)
Eigenvalues & eigenvectors
pinv(A)
Pseudo-inverse
kron(A, B)
Kronecker product
matrixFromRows(...)
Build matrix from row vectors
matrixFromColumns(...)
Build matrix from column vectors
Notes for CalcTree
Use standard
[a, b]and[[a, b], [c, d]]notation for vectors and matrices.Most elementwise operations like
dotMultiply,dotDivide,map, andreshapeare supported.Matrix algebra (
inv,det,transpose, etc.) can be used for linear system calculations.You can pass arrays from tables and use them directly in these functions.
Last updated