nm_ex1.cpp
Go to the documentation of this file.
1 
7 
8 #define WANT_STREAM // include iostream and iomanipulators
9 
10 #include "newmatap.h" // newmat advanced functions
11  // should not be required for this example
12  // included because it seems to help MS VC6
13  // when you have namespace turned on
14 
15 #include "newmatio.h" // newmat headers including output functions
16 
17 #ifdef use_namespace
18 using namespace RBD_LIBRARIES;
19 #endif
20 
21 
22 int my_main() // called by main()
23 {
24  Tracer tr("my_main "); // for tracking exceptions
25 
26  // declare a matrix
27  Matrix X(4,4);
28 
29  // load values row by row
30  X.row(1) << 3.7 << -2.1 << 7.4 << -1.0;
31  X.row(2) << 4.1 << 0.0 << 3.9 << 4.0;
32  X.row(3) << -2.5 << 1.9 << -0.4 << 7.3;
33  X.row(4) << 1.5 << 9.8 << -2.1 << 1.1;
34 
35  // print the matrix
36  cout << "Matrix X" << endl;
37  cout << setw(15) << setprecision(8) << X << endl;
38 
39  // calculate its inverse and print it
40  Matrix Y = X.i();
41  cout << "Inverse of X" << endl;
42  cout << setw(15) << setprecision(8) << Y << endl;
43 
44  // multiply X by its inverse and print the result (should be near identity)
45  cout << "X * inverse of X" << endl;
46  cout << setw(15) << setprecision(8) << (X * Y) << endl;
47 
48  return 0;
49 }
50 
51 
52 // call my_main() - use this to catch exceptions
53 // use macros for exception names for compatibility with simulated exceptions
54 int main()
55 {
56  Try { return my_main(); }
57  Catch(BaseException) { cout << BaseException::what() << "\n"; }
58  CatchAll { cout << "\nProgram fails - exception generated\n\n"; }
59  return 0;
60 }
61 
63 
#define Try
Definition: myexcept.h:190
#define Catch
Definition: myexcept.h:193
int main()
Definition: nm_ex1.cpp:54
#define CatchAll
Definition: myexcept.h:194
The usual rectangular matrix.
Definition: newmat.h:625
InvertedMatrix i() const
Definition: newmat6.cpp:329
static const char * what()
Definition: myexcept.h:93
int my_main()
Definition: nm_ex1.cpp:22
GetSubMatrix row(int) const
Definition: submat.cpp:49


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:16