Esempio n. 1
0
void NRLib::ComputeEigenVectorsComplex(ComplexMatrix        & A,
                                       ComplexVector        & eigen_values,
                                       ComplexMatrix        & eigen_vectors)
{
  ComplexMatrix dummy_mat(A.numRows(), A.numCols());
  flens::ev(false, true, A, eigen_values, dummy_mat, eigen_vectors);
}
Esempio n. 2
0
void NRLib::Adjoint(const ComplexMatrix & in,
                    ComplexMatrix       & out)
{
  int m = out.numRows();
  int n = out.numCols();

  for (int i=0 ; i < m ; i++) {
    for (int j=0 ; j < n ; j++) {
      out(i,j) = std::conj(in(j,i));
    }
  }
}
Esempio n. 3
0
void NRLib::WriteComplexMatrix(const std::string   & header,
                               const ComplexMatrix & C)
{
  int m = C.numRows();
  int n = C.numCols();
  LogKit::LogFormatted(LogKit::Error,"\n"+header+"\n");
  for (int i=0; i < m ; i++) {
    for (int j=0; j < n ; j++) {
      LogKit::LogFormatted(LogKit::Error,"(%12.8f, %12.8f) ",C(i,j).real(),C(i,j).imag());
    }
    LogKit::LogFormatted(LogKit::Error,"\n");
  }
  LogKit::LogFormatted(LogKit::Error,"\n");
}
Esempio n. 4
0
DoubleMatrix mult(DoubleMatrix& m2, ComplexMatrix& m1)
{
    //  Check dimensions
    unsigned int m1_nRows = m1.numRows();
    unsigned int m2_nRows = m2.numRows();
    unsigned int m1_nColumns = m1.numCols();
    unsigned int m2_nColumns = m2.numCols();

    if (m1.size() == 0)
    {
        return real(m1);
    }

    if (m2.size() == 0)
    {
        return m2;
    }

    DoubleMatrix result(m1_nRows, m2_nColumns);
    if (m1_nColumns == m2_nRows)
    {
        for (unsigned int row = 0; row < result.numRows(); row++)
        {
            for (unsigned int col = 0; col < m2_nColumns; col++)
            {
                double sum = 0.0;
                for (unsigned int k = 0; k < m1_nColumns; k++)
                {
                    sum = sum + (real(m1[row][k]) * m2[k][col]);
                }
                result[row][col] = sum;
            }
        }
        return result;
    }

    if (m1_nRows == m2_nColumns)
    {
        return mult(m2, m1);
    }

    throw ("Incompatible matrix operands to multiply");
}