Macro nalgebra::matrix [−][src]
matrix!() { /* proc-macro */ }
Expand description
Construct a fixed-size matrix directly from data.
Note: Requires the macro
feature to be enabled (enabled by default).
This macro facilitates easy construction of matrices when the entries of the matrix are known
(either as constants or expressions). This macro produces an instance of SMatrix
. This means
that the data of the matrix is stored on the stack, and its dimensions are fixed at
compile-time. If you want to construct a dynamic matrix, use dmatrix!
instead.
matrix!
is intended to be both the simplest and most efficient way to construct (small)
matrices, and can also be used in const fn contexts.
The syntax is MATLAB-like. Column elements are separated by a comma (,
), and a semi-colon
(;
) designates that a new row begins.
Examples
use nalgebra::matrix;
// Produces a Matrix3<_> == SMatrix<_, 3, 3>
let a = matrix![1, 2, 3;
4, 5, 6;
7, 8, 9];
You can construct matrices with arbitrary expressions for its elements:
use nalgebra::{matrix, Matrix2};
let theta = 0.45f64;
let r = matrix![theta.cos(), - theta.sin();
theta.sin(), theta.cos()];