Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed vectors&matrices file, userguideUpdate branch #72

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions docs/user_guide/vectors_and_matrices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,83 @@ compile-time.
![Fixed resizing](/img/resizing.svg)

</div>

## Matrix Macros

#### matrix!
Construct a fixed-size matrix directly from data.

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 fncontexts`.

The syntax is MATLAB-like. Column elements are separated by a comma (,), and a semi-colon (;) designates that a new row begins.

```rust
use nalgebra::matrix;

// Produces a Matrix3<_> == SMatrix<_, 3, 3>
let a = matrix![ 1, 2, 3;
4, 5, 6;
7, 8, 9];
```

You can also construct matrices with arbitrary expressions for its elements:

```rust
use nalgebra::{ matrix, Matrix2 };
let theta = 0.45f64;
let r = matrix![ theta.cos(), -theta.sin();
theta.sin(), theta.cos() ];
```

#### vector!

Construct a fixed-size column vector directly from data.

Similarly to `matrix!`, this macro facilitates easy construction of fixed-size vectors. However, whereas the `matrix!` macro expects each row to be separated by a semi-colon, the syntax of this macro is instead similar to `vec!`, in that the elements of the vector are simply listed consecutively.

`vector!` is intended to be the most readable and performant way of constructing small, fixed-size vectors, and it is usable in `const fn` contexts.

```rust
use nalgebra::vector;
// Produces a Vector3<_> == SVector<_, 3>
let v = vector![ 1, 2, 3 ];
```

#### point!
Construct a fixed-size point directly from data.

Similarly to `vector!`, this macro facilitates easy construction of points.

`point!` is intended to be the most readable and performant way of constructing small, points, and it is usable in `const fn` contexts.

```rust
use nalgebra::point;
// Produces a Point3<_>
let v = point![ 1, 2, 3 ];
```

#### dmatrix!
Construct a dynamic matrix directly from data. The syntax is exactly the same as for `matrix!`, but instead of producing instances of `SMatrix`, it produces instances of `DMatrix`.

At the moment it is not usable in `const fn` contexts.

```rust
use nalgebra::dmatrix;
let a = dmatrix![ 1, 2, 3;
4, 5, 6;
7, 8, 9];
```

#### dvector!
Construct a dynamic column vector directly from data.

The syntax is exactly the same as for `vector!`, but instead of producing instances of `SVector`, it produces instances of `DVector`. At the moment it is not usable in `const fn` contexts.

```rust
use nalgebra::dmatrix;
let a = dvector![ 1, 2, 3];
```