This is a test Program for the Class Matrix version 1.6.4
Dependencies: Matrix Kinematics mbed TrackVector2D MatrixMath
Diff: main.cpp
- Revision:
- 0:63af78c5943c
- Child:
- 1:9e4cb305fb24
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 21 03:35:03 2011 +0000 @@ -0,0 +1,94 @@ +#include "mbed.h" +#include "Matrix.h" +#include "MatrixMath.h" + +int main() { + + DigitalOut myled(LED1); + + Matrix myMatrix(3,3); + Matrix anotherMatrix; + + // Fill Matrix with data. + myMatrix << 1 << 2 << 3 + << 4 << 5 << 6 + << 7 << 8 << 9; + + printf( "\myMatrix \n"); + myMatrix.print(); + printf( "\n" ); + + + /** Matrix operations **/ + + // Add 5 to negative Matrix + anotherMatrix = - myMatrix + 5; + + printf( "Result Matrix: anotherMatrix = - myMatrix + 5\n" ); + anotherMatrix.print(); + printf( "\n" ); + + // Matrix Multiplication * + anotherMatrix *= myMatrix; + + printf( "anotherMatrix = anotherMatrix * myMatrix\n" ); + anotherMatrix.print(); + printf( "\n" ); + + // Scalar Matrix Multiplication anotherMatrix *= 0.5 + anotherMatrix *= 0.5; + + printf( "Result Matrix *= 0.5:\n" ); + anotherMatrix.print(); + printf( " _______________________________ \n" ); + + + printf("** MEMBER OPERATIONS ** \n\n"); + + //Copy myMatrix + Matrix temp( myMatrix ); + + // Resize Matrix + temp.Resize(4,4); + printf("\nAdded one Column, one Row to the limitsof myMatrix saved in temp Matrix"); + temp.print(); + + //Delete those new elements, we don't need them anyway. + Matrix::DeleteRow( temp, 4 ); + Matrix::DeleteCol( temp, 4 ); + + printf("\nBack to normal\n"); + temp.print(); + + + // Make room at the begining of Matrix + Matrix::AddRow( temp, 1 ); + Matrix::AddColumn( temp, 1 ); + printf("\nAdded Just one Row and column to the beginning\n"); + temp.print(); + + // Take the second Row as a New Matrix + anotherMatrix = Matrix::ExportRow( temp, 2 ); + printf("\nExport Second Row \n"); + anotherMatrix.print(); + + // The second Column as a ner Matrix, then transpose it to make it a Row + anotherMatrix = Matrix::ExportCol( temp, 2 ); + anotherMatrix = MatrixMath::Transpose( anotherMatrix ); + printf("\nAnd Export Second Column and Transpose it \n"); + anotherMatrix.print(); + + // This will Check to see if your are reduce to a single Row or Column + temp = Matrix::ToPackedVector( myMatrix ); + printf("\nInitial Matrix turned into a single Row\n"); + temp.print(); + + // That's all for now!!! + + while(1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + } +}