tools:matrix:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tools:matrix:start [2021/09/16 17:44] – [Accessing Elements] ursgraf | tools:matrix:start [2022/04/07 12:23] – ursgraf | ||
---|---|---|---|
Line 2: | Line 2: | ||
The blocks in the control system are connected among each other with the aid of signals. As described in [[eeros_architecture: | The blocks in the control system are connected among each other with the aid of signals. As described in [[eeros_architecture: | ||
<code cpp> | <code cpp> | ||
- | | + | Vector< |
- | v << 1.5, -2, 0; | + | |
</ | </ | ||
The declaration could be simplified to | The declaration could be simplified to | ||
<code cpp> | <code cpp> | ||
- | | + | Vector3<> |
- | v << 1.5, -2, 0; | + | |
</ | </ | ||
- | as '' | + | as '' |
<code cpp> | <code cpp> | ||
- | | + | v = {1.5, -2, 0} |
- | m << 1, 4, 7, | + | v << 1.5, -2, 0; // or with input operator |
- | 2, 5, 8, | + | Vector3 v{1,2,3}; // or directly upon declaration |
- | 3, 6, 9; | + | </ |
+ | A matrix of 3 times 3 with element type '' | ||
+ | <code cpp> | ||
+ | Matrix< | ||
+ | m << 1, 2, 3, | ||
+ | 4, 5, 6, | ||
+ | 7, 8, 9; | ||
</ | </ | ||
The first three numbers will be filled into the first colon. While the internal representation is simply a one dimensional vector, the matrix could be visualized as | The first three numbers will be filled into the first colon. While the internal representation is simply a one dimensional vector, the matrix could be visualized as | ||
- | + | | ^col0^col1^col2^ | |
- | | 1 | 2 | 3 | | + | ^row0|1|2|3| |
- | | 4 | 5 | 6 | | + | ^row1|4|5|6| |
- | | 7 | 8 | 9 | | + | ^row2|7|8|9| |
===== Accessing Elements ===== | ===== Accessing Elements ===== | ||
Line 28: | Line 32: | ||
<code cpp> | <code cpp> | ||
m.get(0, | m.get(0, | ||
+ | m.get(1, | ||
m.getRow(1); | m.getRow(1); | ||
m.getCol(0); | m.getCol(0); | ||
Line 43: | Line 48: | ||
===== Logging Matrices ===== | ===== Logging Matrices ===== | ||
+ | A matrix can be logged simply by writing | ||
+ | <code cpp> | ||
+ | log.info() << m; | ||
+ | </ | ||
+ | With the 3 x 3 matrix from above we would get | ||
+ | < | ||
+ | 2021-09-16 17: | ||
+ | </ | ||
+ | The matrix is plotted colon per colon. To give some more examples: | ||
+ | <code cpp> | ||
+ | Matrix< | ||
+ | Matrix< | ||
+ | Matrix< | ||
+ | </ | ||
+ | This matrices will be printed as | ||
+ | < | ||
+ | 2021-09-16 17: | ||
+ | 2021-09-16 17: | ||
+ | 2021-09-16 17: | ||
+ | </ | ||
+ | |||
+ | ===== Matrix Operations ===== | ||
+ | Some examples show basic matrix operations. | ||
+ | <code cpp> | ||
+ | Vector2 v1{1,2}; | ||
+ | Matrix< | ||
+ | log.info() << v1 * v2; // will print [ [3 6]' [4 8]' ] | ||
+ | log.info() << v2 * v1; // will print [11]' | ||
+ | |||
+ | Matrix< | ||
+ | log.info() << v2 * m1; // will print [ [9]' [5]' ] | ||
+ | log.info() << v1.transpose() * m1;// will print [ [4]' [3]' ] | ||
+ | |||
+ | auto x = v2 * m1; | ||
+ | Vector2 v4 = x.transpose(); | ||
+ | log.info() << v4; // will print [9 5]' | ||
+ | </ |
tools/matrix/start.txt · Last modified: 2022/04/20 13:29 by ursgraf