Matrix functions
The functions that work on vectors and matrices, one entry each. For writing a matrix, indexing it and the bars |M|, see Matrices; the table functions, which read a matrix as a table, are on Table functions, and everything else on Built-in functions.
column
Section titled “column”column(M, j)One column of a matrix, counting from 1.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
M |
A matrix with rows and columns. A table block’s name works too. See Tables. |
j |
The column number, from 1. |
Returns
Section titled “Returns”The column, as an matrix.
Errors
Section titled “Errors”| Message | When |
|---|---|
| Only two dimensional matrix is supported | M is a plain list rather than a matrix with rows and columns |
| Index out of range | j is below 1 or past the last column |
| Index must be an integer | j isn’t a whole number |
Example
Section titled “Example”cross(a, b)The cross product of two three-dimensional vectors.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
a |
A vector of exactly three elements. |
b |
A vector of exactly three elements. |
Returns
Section titled “Returns”The vector .
Errors
Section titled “Errors”| Message | When |
|---|---|
| Vectors with length 3 expected | Either vector doesn’t have three elements |
| Too few arguments in function cross / Too many arguments in function cross | Not exactly two arguments |
Example
Section titled “Example”det(M)The determinant of a square matrix. The bars |M| around a square matrix mean the same thing.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
M |
A square matrix. |
Returns
Section titled “Returns”A number.
Errors
Section titled “Errors”| Message | When |
|---|---|
| Matrix must be square | M isn’t square, or is a plain list |
| Too few arguments in function det / Too many arguments in function det | Not exactly one argument |
Example
Section titled “Example”dot(a, b)The dot product of two vectors of the same length. Units multiply through.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
a |
A vector: a plain list or a column matrix. |
b |
A vector of the same length. |
Returns
Section titled “Returns”A number, or a quantity whose units are the product of the two vectors’ units.
Errors
Section titled “Errors”| Message | When |
|---|---|
| Vectors must have equal length | The two vectors differ in length |
| Too few arguments in function dot / Too many arguments in function dot | Not exactly two arguments |
Example
Section titled “Example”inv(M)The inverse of a square matrix. Of a plain number, its reciprocal.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
M |
A square, non-singular matrix, or a number. |
Returns
Section titled “Returns”The inverse matrix, or for a number.
Errors
Section titled “Errors”| Message | When |
|---|---|
| Cannot calculate inverse, determinant is zero | M is singular |
| Matrix must be square | M isn’t square |
| Too few arguments in function inv / Too many arguments in function inv | Not exactly one argument |
Example
Section titled “Example”norm(v)norm(v, p)norm(M)The length of a vector, the everyday case, including a vector of quantities, as long as they share a unit. Of a matrix, the Frobenius norm; of a number, its magnitude. The bars |v| around a vector mean the same thing, and also accept a column written as a matrix, which norm itself does not.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
v |
A vector written as a plain list, of numbers or of quantities with one unit. |
p |
Optional. The kind of norm: 2 (default, Euclidean), 1 (sum of magnitudes), Infinity (largest magnitude), or 'fro'. |
M |
A matrix with rows and columns. |
Returns
Section titled “Returns”The length, in the unit of the first element; a number for plain values.
Errors
Section titled “Errors”| Message | When |
|---|---|
| The length of a vector needs every element in the same unit | Some elements carry a unit and others don’t, or the units differ in kind |
| Invalid matrix dimensions | A column vector written as an matrix. Use the bars, or a plain list |
| Too few arguments in function norm / Too many arguments in function norm | No argument, or more than two |
Example
Section titled “Example”row(M, i)One row of a matrix, counting from 1.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
M |
A matrix with rows and columns. A table block’s name works too. See Tables. |
i |
The row number, from 1. |
Returns
Section titled “Returns”The row, as a matrix.
Errors
Section titled “Errors”| Message | When |
|---|---|
| Only two dimensional matrix is supported | M is a plain list rather than a matrix with rows and columns |
| Index out of range | i is below 1 or past the last row |
| Index must be an integer | i isn’t a whole number |
Example
Section titled “Example”transpose
Section titled “transpose”transpose(M)Swaps a matrix’s rows and columns. The toolbar’s is the same function. A plain list has no second dimension, so it comes back unchanged; write a column as a matrix to transpose it into a row.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
M |
A matrix. |
Returns
Section titled “Returns”The transposed matrix.
Errors
Section titled “Errors”| Message | When |
|---|---|
| Too few arguments in function transpose / Too many arguments in function transpose | Not exactly one argument |
