⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nm_ex1.cpp

📁 非常好用的用C编写的矩阵类,可在不同编译器下编译使用.
💻 CPP
字号:
/// \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;
}

///@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -