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"); }
void run_ensemble(const char* fname, unsigned long seed) { try { RoadRunner r(fname); DoubleMatrix result = ensemble(r, 5, seed, 0, 10, 150); cout.precision(6); for(int row = 0; row < result.numRows(); ++row) { for(int col = 0; col < result.numCols(); ++col) { cout << result(row, col) << ", "; } cout << endl; } } catch (std::exception& e) { cout << "Error running ensemble: " << e.what() << endl; } }