forked from phuicy/ROBOOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnm_ex1.cpp
63 lines (46 loc) · 1.73 KB
/
nm_ex1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/// \ingroup newmat
///@{
/// \file nm_ex1.cpp
/// Very simple example 1.
/// Invert a 4 x 4 matrix then check the result
#define WANT_STREAM // include iostream and iomanipulators
#include "newmatap.h" // newmat advanced functions
// should not be required for this example
// included because it seems to help MS VC6
// when you have namespace turned on
#include "newmatio.h" // newmat headers including output functions
#ifdef use_namespace
using namespace RBD_LIBRARIES;
#endif
int my_main() // called by main()
{
Tracer tr("my_main "); // for tracking exceptions
// declare a matrix
Matrix X(4,4);
// load values row by row
X.row(1) << 3.7 << -2.1 << 7.4 << -1.0;
X.row(2) << 4.1 << 0.0 << 3.9 << 4.0;
X.row(3) << -2.5 << 1.9 << -0.4 << 7.3;
X.row(4) << 1.5 << 9.8 << -2.1 << 1.1;
// print the matrix
cout << "Matrix X" << endl;
cout << setw(15) << setprecision(8) << X << endl;
// calculate its inverse and print it
Matrix Y = X.i();
cout << "Inverse of X" << endl;
cout << setw(15) << setprecision(8) << Y << endl;
// multiply X by its inverse and print the result (should be near identity)
cout << "X * inverse of X" << endl;
cout << setw(15) << setprecision(8) << (X * Y) << endl;
return 0;
}
// call my_main() - use this to catch exceptions
// use macros for exception names for compatibility with simulated exceptions
int main()
{
Try { return my_main(); }
Catch(BaseException) { cout << BaseException::what() << "\n"; }
CatchAll { cout << "\nProgram fails - exception generated\n\n"; }
return 0;
}
///@}