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 1 commit
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
66 changes: 66 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,69 @@ compile-time.
![Fixed resizing](/img/resizing.svg)

</div>

## Matrix Macros
### Macros
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we should remove hte ### Macros header because it just causes unnecessary nesting in the navigation (on the right side).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed the header.

#### 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use code blocks for vectors, types etc, so that it's consistent with the rest of the user guide. This applies throughout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated: Ok I tried to make sure and use code blocks for types, vectors, etc. so I could match the rest of the document.

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];
```
#### 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not properly aligned

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated:

I updated the spacing between paragraphs to try and match the rest of the document. Hopefully I understood correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was not clear: I meant that the matrix elements are not aligned, e.g. the 4 appears one character to the left of 1, which looks odd. Please remove the new line after the comment again!

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() ];
```

#### 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 ];
```

#### 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 ];
```