-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
7ece318
697f1f3
4cb0959
6c9192c
f767b87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -501,3 +501,69 @@ compile-time. | |
![Fixed resizing](/img/resizing.svg) | ||
|
||
</div> | ||
|
||
## Matrix Macros | ||
### Macros | ||
#### 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not properly aligned There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 ]; | ||
``` |
There was a problem hiding this comment.
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).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, removed the header.