This is a test Program for the Class Matrix version 1.6.4
Dependencies: Matrix Kinematics mbed TrackVector2D MatrixMath
main.cpp@0:63af78c5943c, 2011-10-21 (annotated)
- Committer:
- Yo_Robot
- Date:
- Fri Oct 21 03:35:03 2011 +0000
- Revision:
- 0:63af78c5943c
- Child:
- 1:9e4cb305fb24
Example program to show MatrixClass
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 0:63af78c5943c | 1 | #include "mbed.h" |
Yo_Robot | 0:63af78c5943c | 2 | #include "Matrix.h" |
Yo_Robot | 0:63af78c5943c | 3 | #include "MatrixMath.h" |
Yo_Robot | 0:63af78c5943c | 4 | |
Yo_Robot | 0:63af78c5943c | 5 | int main() { |
Yo_Robot | 0:63af78c5943c | 6 | |
Yo_Robot | 0:63af78c5943c | 7 | DigitalOut myled(LED1); |
Yo_Robot | 0:63af78c5943c | 8 | |
Yo_Robot | 0:63af78c5943c | 9 | Matrix myMatrix(3,3); |
Yo_Robot | 0:63af78c5943c | 10 | Matrix anotherMatrix; |
Yo_Robot | 0:63af78c5943c | 11 | |
Yo_Robot | 0:63af78c5943c | 12 | // Fill Matrix with data. |
Yo_Robot | 0:63af78c5943c | 13 | myMatrix << 1 << 2 << 3 |
Yo_Robot | 0:63af78c5943c | 14 | << 4 << 5 << 6 |
Yo_Robot | 0:63af78c5943c | 15 | << 7 << 8 << 9; |
Yo_Robot | 0:63af78c5943c | 16 | |
Yo_Robot | 0:63af78c5943c | 17 | printf( "\myMatrix \n"); |
Yo_Robot | 0:63af78c5943c | 18 | myMatrix.print(); |
Yo_Robot | 0:63af78c5943c | 19 | printf( "\n" ); |
Yo_Robot | 0:63af78c5943c | 20 | |
Yo_Robot | 0:63af78c5943c | 21 | |
Yo_Robot | 0:63af78c5943c | 22 | /** Matrix operations **/ |
Yo_Robot | 0:63af78c5943c | 23 | |
Yo_Robot | 0:63af78c5943c | 24 | // Add 5 to negative Matrix |
Yo_Robot | 0:63af78c5943c | 25 | anotherMatrix = - myMatrix + 5; |
Yo_Robot | 0:63af78c5943c | 26 | |
Yo_Robot | 0:63af78c5943c | 27 | printf( "Result Matrix: anotherMatrix = - myMatrix + 5\n" ); |
Yo_Robot | 0:63af78c5943c | 28 | anotherMatrix.print(); |
Yo_Robot | 0:63af78c5943c | 29 | printf( "\n" ); |
Yo_Robot | 0:63af78c5943c | 30 | |
Yo_Robot | 0:63af78c5943c | 31 | // Matrix Multiplication * |
Yo_Robot | 0:63af78c5943c | 32 | anotherMatrix *= myMatrix; |
Yo_Robot | 0:63af78c5943c | 33 | |
Yo_Robot | 0:63af78c5943c | 34 | printf( "anotherMatrix = anotherMatrix * myMatrix\n" ); |
Yo_Robot | 0:63af78c5943c | 35 | anotherMatrix.print(); |
Yo_Robot | 0:63af78c5943c | 36 | printf( "\n" ); |
Yo_Robot | 0:63af78c5943c | 37 | |
Yo_Robot | 0:63af78c5943c | 38 | // Scalar Matrix Multiplication anotherMatrix *= 0.5 |
Yo_Robot | 0:63af78c5943c | 39 | anotherMatrix *= 0.5; |
Yo_Robot | 0:63af78c5943c | 40 | |
Yo_Robot | 0:63af78c5943c | 41 | printf( "Result Matrix *= 0.5:\n" ); |
Yo_Robot | 0:63af78c5943c | 42 | anotherMatrix.print(); |
Yo_Robot | 0:63af78c5943c | 43 | printf( " _______________________________ \n" ); |
Yo_Robot | 0:63af78c5943c | 44 | |
Yo_Robot | 0:63af78c5943c | 45 | |
Yo_Robot | 0:63af78c5943c | 46 | printf("** MEMBER OPERATIONS ** \n\n"); |
Yo_Robot | 0:63af78c5943c | 47 | |
Yo_Robot | 0:63af78c5943c | 48 | //Copy myMatrix |
Yo_Robot | 0:63af78c5943c | 49 | Matrix temp( myMatrix ); |
Yo_Robot | 0:63af78c5943c | 50 | |
Yo_Robot | 0:63af78c5943c | 51 | // Resize Matrix |
Yo_Robot | 0:63af78c5943c | 52 | temp.Resize(4,4); |
Yo_Robot | 0:63af78c5943c | 53 | printf("\nAdded one Column, one Row to the limitsof myMatrix saved in temp Matrix"); |
Yo_Robot | 0:63af78c5943c | 54 | temp.print(); |
Yo_Robot | 0:63af78c5943c | 55 | |
Yo_Robot | 0:63af78c5943c | 56 | //Delete those new elements, we don't need them anyway. |
Yo_Robot | 0:63af78c5943c | 57 | Matrix::DeleteRow( temp, 4 ); |
Yo_Robot | 0:63af78c5943c | 58 | Matrix::DeleteCol( temp, 4 ); |
Yo_Robot | 0:63af78c5943c | 59 | |
Yo_Robot | 0:63af78c5943c | 60 | printf("\nBack to normal\n"); |
Yo_Robot | 0:63af78c5943c | 61 | temp.print(); |
Yo_Robot | 0:63af78c5943c | 62 | |
Yo_Robot | 0:63af78c5943c | 63 | |
Yo_Robot | 0:63af78c5943c | 64 | // Make room at the begining of Matrix |
Yo_Robot | 0:63af78c5943c | 65 | Matrix::AddRow( temp, 1 ); |
Yo_Robot | 0:63af78c5943c | 66 | Matrix::AddColumn( temp, 1 ); |
Yo_Robot | 0:63af78c5943c | 67 | printf("\nAdded Just one Row and column to the beginning\n"); |
Yo_Robot | 0:63af78c5943c | 68 | temp.print(); |
Yo_Robot | 0:63af78c5943c | 69 | |
Yo_Robot | 0:63af78c5943c | 70 | // Take the second Row as a New Matrix |
Yo_Robot | 0:63af78c5943c | 71 | anotherMatrix = Matrix::ExportRow( temp, 2 ); |
Yo_Robot | 0:63af78c5943c | 72 | printf("\nExport Second Row \n"); |
Yo_Robot | 0:63af78c5943c | 73 | anotherMatrix.print(); |
Yo_Robot | 0:63af78c5943c | 74 | |
Yo_Robot | 0:63af78c5943c | 75 | // The second Column as a ner Matrix, then transpose it to make it a Row |
Yo_Robot | 0:63af78c5943c | 76 | anotherMatrix = Matrix::ExportCol( temp, 2 ); |
Yo_Robot | 0:63af78c5943c | 77 | anotherMatrix = MatrixMath::Transpose( anotherMatrix ); |
Yo_Robot | 0:63af78c5943c | 78 | printf("\nAnd Export Second Column and Transpose it \n"); |
Yo_Robot | 0:63af78c5943c | 79 | anotherMatrix.print(); |
Yo_Robot | 0:63af78c5943c | 80 | |
Yo_Robot | 0:63af78c5943c | 81 | // This will Check to see if your are reduce to a single Row or Column |
Yo_Robot | 0:63af78c5943c | 82 | temp = Matrix::ToPackedVector( myMatrix ); |
Yo_Robot | 0:63af78c5943c | 83 | printf("\nInitial Matrix turned into a single Row\n"); |
Yo_Robot | 0:63af78c5943c | 84 | temp.print(); |
Yo_Robot | 0:63af78c5943c | 85 | |
Yo_Robot | 0:63af78c5943c | 86 | // That's all for now!!! |
Yo_Robot | 0:63af78c5943c | 87 | |
Yo_Robot | 0:63af78c5943c | 88 | while(1) { |
Yo_Robot | 0:63af78c5943c | 89 | myled = 1; |
Yo_Robot | 0:63af78c5943c | 90 | wait(0.2); |
Yo_Robot | 0:63af78c5943c | 91 | myled = 0; |
Yo_Robot | 0:63af78c5943c | 92 | wait(0.2); |
Yo_Robot | 0:63af78c5943c | 93 | } |
Yo_Robot | 0:63af78c5943c | 94 | } |