Matrices and vectors#
Literals and indexing#
A vector is [1,2,3]. A matrix is [1,2;3,4] or [[1,2],[3,4]]. Every row must have the same length. Indices start at 1 in cell expressions.
A = [1,2;3,4]
A[1,2]
A[:,1]
size(A)Interactive examples could not load. You can still copy the expressions.
Arithmetic#
* performs matrix multiplication for compatible matrices. Use .*, ./, and .^ to work entry by entry. A matrix product needs the left column count to match the right row count.
[1,2;3,4] * [1;2]
[1,2;3,4] .* [2,2;2,2]Interactive examples could not load. You can still copy the expressions.
Build and reshape#
zeros, ones, identity, diag, range, reshape, flatten, squeeze, concat, matrixFromRows, matrixFromColumns, and matrixFromFunction construct or reshape. sparse stores a mostly-zero matrix sparsely. row, column, subset, index, map, filter, and mapSlices select or transform data.
Linear algebra#
det, inv, trace, transpose, ctranspose, norm, dot, cross, and kron cover the common operations. The advanced set adds pinv, eigs, qr, lup, slu, schur, lsolve, usolve, lusolve, their all-solutions variants, lyap, and sylvester.
a = [-2, 3; 2, 1]
b = [11, 9]
x = lusolve(a, b)Interactive examples could not load. You can still copy the expressions.
A singular matrix has no inverse. A pseudoinverse is a different operation, not a guarantee of an exact solution. Decomposition and eigenvalue functions return structured information, so inspect the result and use the function's own example for its shape.
Geometry and signal processing#
rotate, rotationMatrix, distance, and intersect cover geometry. fft, ifft, freqz, and zpk2tf cover signal and control calculations. Check each reference for the array shapes and optional arguments.
Results#
Results render as tables where possible. A data array can also become a scatter plot, bar chart, or histogram.