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

📄 test_lu.cpp

📁 This collection of C++ templates wraps the FORTRAN or C interfaces for LAPACK so that they integrate
💻 CPP
字号:

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

#include <vector>
#include <iostream>
#include <time.h>

#include "lufactor.hpp"
#include "printmatrix.hpp"

using namespace boost::numeric::ublas;
using namespace ulapack;
using namespace std;

int main( ) 
{
	try {
		typedef matrix<double, column_major> Matrix;
		Matrix m( 4,4 );

		//srand(time(0));

		for (int i=0; i<m.size1(); ++i)
			for (int j=0; j<m.size2(); ++j)
				m(i,j) = rand();

		cout << "Original matrix: " << endl;
		print_matrix(m);

#if 1 // test LU class
		LU<Matrix> lu(m);

		cout << "LU inverse: " << endl;
		print_matrix(lu.inv());

		cout << "LU determinant: " << lu.det() << endl;

#else // test LU stand-alone functions
		Matrix lu(m);
		ublas::vector<int> pivot;

		const char *status = (lufactor(lu, pivot)==false) ? "Singular" : "Non-singular";
		cout << status << " LU factorised matrix: " << endl;
		print_matrix(lu);

		Matrix x = inv(m);
		cout << "Inverse" << endl;
		print_matrix(x);

		cout << "LU determinant: " << det(m) << endl;
#endif

	}
	catch (LapackError& e) {
		cout << "LapackError, INFO: " << e.get_info()
			<< " Message: " << e.what() << endl;
	}
	catch (exception& e) {
		cout << "Other Exception, Message: " << e.what() << endl;
	}
	catch (...) {
		cout << "Unknown Exception" << endl;
	}

}

⌨️ 快捷键说明

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