1

プロジェクトの決定要因を計算する必要があります。C++ 14 と Eigen を使用しています。

したがって、MatrixXd A は X 行 X 列の固有行列であり、double 値を含みます。行列式を計算するには、A.determinant() を使用します。A.determinant() が d に等しいとしましょう。次に、R.determinant() が -d に等しいため、QR 分解を使用すると問題が発生し、d に等しくなるはずです。これは、大きな行列でのみ発生しました (サイズが 5 を超える - 私はこれを観察しました)。記号だけが問題なのですが、なぜですか?

私のコード:

#include <iostream>
#include <Eigen>
#include <fstream>
#include <chrono>
using namespace Eigen;
using namespace std;
using namespace std::chrono;
ifstream fin("input.txt");

int main()
{
    double aux;
    int n = 10;
    MatrixXd A;
    A.resize(n,n);

    // Read A
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            fin>>aux;
            A(i,j) = aux;
        }
    cout<<"Start!"<<endl;
    cout<<A.determinant()<<endl;


    //Use QR decomposition, get R matrix
    HouseholderQR<MatrixXd> qr(A);
    qr.compute(A);
    MatrixXd R = qr.matrixQR().template  triangularView<Upper>();

    // R is a triangular matrix, det(A) should be equal to det(R)
    cout<<R.determinant()<<endl;

    return 0;
}

どうすればこれを解決できますか? 画像

4

0 に答える 0