구해 행렬 방정식 소모 시간 비교(직접 역구, Qr분해, LU분해)
2176 단어 slam
테스트 환경:
코드
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace Eigen;
/***********************
* solve equation: matrix_NN * x = v_Nd
************************/
const int MATRIX_SIZE = 100;
// https://blog.csdn.net/weixin_41074793/article/details/84241776
int main()
{
Matrix< double, MATRIX_SIZE, MATRIX_SIZE > matrix_NN;
matrix_NN = MatrixXd::Random( MATRIX_SIZE, MATRIX_SIZE );
Matrix v_Nd;
v_Nd = MatrixXd::Random( MATRIX_SIZE,1);
clock_t time_stt = clock();
//
Matrix< double, MATRIX_SIZE, 1> x = matrix_NN.inverse()*v_Nd;
cout << "time use in normal inverse is " << 1000.0 * (clock() - time_stt) /
(double)CLOCKS_PER_SEC << "ms" << endl;
//Qr
time_stt = clock();
x = matrix_NN.colPivHouseholderQr().solve(v_Nd);
cout << "time use in Qr composition is " << 1000 * (clock() - time_stt) / (double)
CLOCKS_PER_SEC << "ms" << endl;
//cholesky
time_stt = clock();
// NN ,
matrix_NN = matrix_NN.transpose() * matrix_NN;
x = matrix_NN.partialPivLu().solve(v_Nd);
cout << "time use in cholesky composition is " << 1000 * (clock() - time_stt) / (double)
CLOCKS_PER_SEC << "ms" << endl;
//LU
time_stt = clock();
x = matrix_NN.partialPivLu().solve(v_Nd);
cout << "time use in LU composition is " << 1000 * (clock() - time_stt) / (double)
CLOCKS_PER_SEC << "ms" << endl;
return 0;
}
#### 결과
time use in normal inverse is 1547.72ms time use in Qr composition is 37.475ms time use in cholesky composition is 13.074ms time use in LU composition is 5.242ms
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
고상slam14강 중ch7 코드 중 일부 수정카탈로그 문제1:opencv버전 문제, 컴파일 오류. 문제2:./ch7/pose_estimation_3d2d.cpp:43:35: error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.