nm_ex1.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00007 
00008 #define WANT_STREAM       // include iostream and iomanipulators
00009 
00010 #include "newmatap.h"     // newmat advanced functions
00011                           // should not be required for this example
00012                           // included because it seems to help MS VC6
00013                           // when you have namespace turned on
00014                            
00015 #include "newmatio.h"     // newmat headers including output functions
00016 
00017 #ifdef use_namespace
00018 using namespace RBD_LIBRARIES;
00019 #endif
00020 
00021 
00022 int my_main()                  // called by main()
00023 {
00024    Tracer tr("my_main ");      // for tracking exceptions
00025 
00026    // declare a matrix
00027    Matrix X(4,4);
00028    
00029    // load values row by row
00030    X.row(1) <<  3.7 << -2.1 <<  7.4 << -1.0;
00031    X.row(2) <<  4.1 <<  0.0 <<  3.9 <<  4.0;
00032    X.row(3) << -2.5 <<  1.9 << -0.4 <<  7.3;
00033    X.row(4) <<  1.5 <<  9.8 << -2.1 <<  1.1;
00034 
00035    // print the matrix
00036    cout << "Matrix X" << endl;
00037    cout << setw(15) << setprecision(8) << X << endl;
00038    
00039    // calculate its inverse and print it
00040    Matrix Y = X.i();
00041    cout << "Inverse of X" << endl;
00042    cout << setw(15) << setprecision(8) << Y << endl;
00043    
00044    // multiply X by its inverse and print the result (should be near identity)
00045    cout << "X * inverse of X" << endl;
00046    cout << setw(15) << setprecision(8) << (X * Y) << endl;
00047    
00048    return 0;
00049 }
00050 
00051 
00052 // call my_main() - use this to catch exceptions
00053 // use macros for exception names for compatibility with simulated exceptions
00054 int main()
00055 {
00056    Try  { return my_main(); }
00057    Catch(BaseException) { cout << BaseException::what() << "\n"; }
00058    CatchAll { cout << "\nProgram fails - exception generated\n\n"; }
00059    return 0;
00060 }
00061 
00063 


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Mon Oct 6 2014 10:45:33