dimanche 21 avril 2019

Problem with Matrix Size or Type in Eigen

When I run the following piece of code

        double X2 = 0.0;
        MatrixXd pf,Sigma;
        MatrixXcd P, K, rho, I;
        int n = 2;
        int R = 3;
        //cout << "Channels: " << endl;
        //cin >> n;
        //cout << "Resonances: " << endl;
        //cin >> R;
        double m_f[2];
        cout << "Final states masses: " << '\n';
        for (int index = 0; index < n; index++){
            cout << "m_f" << index + 1 << " = ";
            cin >> m_f[index];
        }
        for (int i = 0; i < _data[0].size(); i++){
            double x = _data[0][i];
            double y = _data[1][i];
            double err = _data[2][i];
            double pi = sqrt((x*x)/4- 0.000511*0.000511);

            pf = MatrixXd(1,n);
            for (int col = 0; col < n; col++){
                    pf(0,col) = sqrt((x*x)/4 - m_f[col]*m_f[col]);
            }

            P = MatrixXcd(1,n);
            for (int col = 0; col < n; col++){
                    for (int resTerm = 0; resTerm < R; resTerm++){
                        P(0,col) += params[resTerm+2*col]*params[resTerm]/(x*x - params[R*n+resTerm]*params[R*n+resTerm]+1e-8);
                    }
            }

            K = MatrixXcd(n,n);
            for (int col = 0; col < n; col++){
                for (int row = 0; row < n; row++){
                    for (int resTerm = 0; resTerm < R; resTerm++){
                    K(row,col) += params[resTerm+2*col]*params[resTerm+2*row]/(x*x - params[R*n+resTerm]*params[R*n+resTerm]+1e-8);
                    }
                }
            }

            rho = MatrixXcd(n,n);
            for (int col = 0; col < n; col++){
                for (int row = 0; row < n; row++){
                    if(row != col){
                        rho(row,col) = 0;
                    }
                    else{
                    rho(row,col) = sqrt((x*x/4) - m_f[row]*m_f[row]);
                    }
                }
            }

            I = MatrixXcd::Identity(n,n);
            MatrixXcd A = (I + im*rho*K);
            MatrixXcd T = P*A.inverse(); // 1xn matrix

            Sigma = (1/(64*3.14159*x*x))*(pf/pi)*T.real()*T.real(); // 1xn matrix
            for (int col = 0; col < n; col++){
                Sigma = (1/(64*3.14159*x*x))*(pf(0,col)/pi)*T(0,col)*conj(T(0,col)); // 1xn matrix
                X2 += (_data[1][i]-Sigma(0,col))*(_data[1][i]-Sigma(0,col))/(_data[2][i]*_data[2][i]);
                }
        }
          return X2;
    }

I get the following error:

newGeneral: /usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h:337: Eigen::DenseCoeffsBase::Scalar& Eigen::DenseCoeffsBase::operator()(Eigen::DenseCoeffsBase::Index, Eigen::DenseCoeffsBase::Index) [with Derived = Eigen::Matrix, -1, -1>; Eigen::DenseCoeffsBase::Scalar = std::complex; Eigen::DenseCoeffsBase::Index = long int]: Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed. Aborted

I am not even sure what this error means, but I think it has to do with the size or type of the matrices involved. Any help would be much appreciated.

Thanks.

Aucun commentaire:

Enregistrer un commentaire