40 template <
class Tmplt>
76 if (&mm ==
this)
return *
this;
89 if (&mm ==
this)
return *
this;
118 template <
class Tmplt>
123 template <
class Tmplt>
126 for (
size_t a = 1; a <= i; a++)
127 for (
size_t b = 1; b <= j; b++)
128 operator()(a, b) = value;
131 template <
class Tmplt>
136 template <
class Tmplt>
139 for (
size_t a = 1; a <= i; a++) {
140 for (
size_t b = 1; b < a; b++)
141 mm(a, b) = off_diag_value;
142 for (
size_t b = a + 1; b <= i; b++)
143 mm(a, b) = off_diag_value;
144 mm(a, a) = diag_value;
149 template <
class Tmplt>
169 for (
size_t a = 0; a < i; a++)
170 for (
size_t b = 0; b < j; b++)
171 operator()(a + 1, b + 1) = data[b * i + a];
177 for (
size_t a = 0; a < i; a++)
178 for (
size_t b = 0; b < j; b++)
179 operator()(a + 1, b + 1) = data[b * i + a];
188 if (num_row() != num_col())
190 "MMatrix::determinant()",
"Attempt to get determinant of non-square matrix"));
201 if (num_row() != num_col())
203 "MMatrix::determinant()",
"Attempt to get determinant of non-square matrix"));
212 template <
class Tmplt>
221 if (num_row() != num_col())
223 "MMatrix::invert()",
"Attempt to get inverse of non-square matrix"));
231 for (
size_t i = 1; i <= num_row(); i++)
232 for (
size_t j = 1; j <= num_row(); j++)
233 if (
operator()(i, j) !=
operator()(i, j))
235 "MMatrix::invert()",
"Failed to invert matrix - singular?"));
240 if (num_row() != num_col())
242 "MMatrix::invert()",
"Attempt to get inverse of non-square matrix"));
249 for (
size_t i = 1; i <= num_row(); i++)
250 for (
size_t j = 1; j <= num_row(); j++)
251 if (
operator()(i, j) !=
operator()(i, j))
253 "MMatrix::invert()",
"Failed to invert matrix - singular?"));
271 template <
class Tmplt>
273 size_t min_row,
size_t max_row,
size_t min_col,
size_t max_col)
const {
274 MMatrix<Tmplt> sub_matrix(max_row - min_row + 1, max_col - min_col + 1);
275 for (
size_t i = min_row; i <= max_row; i++)
276 for (
size_t j = min_col; j <= max_col; j++)
277 sub_matrix(i - min_row + 1, j - min_col + 1) = operator()(i, j);
281 size_t min_row,
size_t max_row,
size_t min_col,
size_t max_col)
const;
283 size_t min_row,
size_t max_row,
size_t min_col,
size_t max_col)
const;
285 template <
class Tmplt>
287 Tmplt t = operator()(1, 1);
288 for (
size_t i = 2; i <= num_row() && i <= num_col(); i++)
289 t +=
operator()(i, i);
295 template <
class Tmplt>
297 if (num_row() != num_col())
299 "MMatrix<double>::eigenvalues",
300 "Attempt to get eigenvectors of non-square matrix"));
309 "MMatrix<Tmplt>::eigenvalues",
"Failed to calculate eigenvalue"));
314 template <
class Tmplt>
316 if (num_row() != num_col())
318 "MMatrix<double>::eigenvectors",
319 "Attempt to get eigenvectors of non-square matrix"));
329 "MMatrix<Tmplt>::eigenvectors",
"Failed to calculate eigenvalue"));
356 template <
class Tmplt>
359 for (
size_t i = 1; i <= mat.
num_row(); i++) {
361 for (
size_t j = 1; j < mat.
num_col(); j++)
362 out << mat(i, j) <<
" ";
363 out << mat(i, mat.
num_col()) <<
"\n";
370 template <
class Tmplt>
375 for (
size_t i = 1; i <=
nr; i++)
376 for (
size_t j = 1; j <= nc; j++)
385 for (
size_t i = 1; i <= mc.
num_row(); i++)
386 for (
size_t j = 1; j <= mc.
num_col(); j++)
387 md(i, j) =
re(mc(i, j));
393 for (
size_t i = 1; i <= mc.
num_row(); i++)
394 for (
size_t j = 1; j <= mc.
num_col(); j++)
395 md(i, j) =
im(mc(i, j));
401 for (
size_t i = 1; i <= mc.
num_row(); i++)
402 for (
size_t j = 1; j <= mc.
num_col(); j++)
410 "MMatrix<m_complex>::complex",
411 "Attempt to build complex matrix when real and imaginary matrix don't have the "
414 for (
size_t i = 1; i <= mc.
num_row(); i++)
415 for (
size_t j = 1; j <= mc.
num_col(); j++)
420 template <
class Tmplt>
423 for (
size_t i = 1; i <= num_row(); i++)
424 temp(i) = operator()(i, column);
void gsl_blas_zgemm(CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB, gsl_complex alpha, const gsl_matrix_complex *A, const gsl_matrix_complex *B, gsl_complex beta, gsl_matrix_complex *C)
Complex matrix-matrix multiply and accumulate.
void gsl_blas_dgemm(CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB, double alpha, const gsl_matrix *A, const gsl_matrix *B, double beta, gsl_matrix *C)
Real matrix-matrix multiply and accumulate.
void gsl_eigen_nonsymmv_free(gsl_eigen_nonsymmv_workspace *w)
Free a workspace allocated by gsl_eigen_nonsymmv_alloc.
int gsl_eigen_nonsymm(gsl_matrix *A, gsl_vector_complex *eval, gsl_eigen_nonsymm_workspace *)
Compute eigenvalues of a real nonsymmetric matrix.
int gsl_eigen_nonsymmv(gsl_matrix *A, gsl_vector_complex *eval, gsl_matrix_complex *evec, gsl_eigen_nonsymmv_workspace *w)
Compute eigenvalues and a simplified set of eigenvectors.
void gsl_eigen_nonsymm_params(int, int, gsl_eigen_nonsymm_workspace *)
Accept GSL-style parameters (no-op in this implementation).
gsl_eigen_nonsymm_workspace * gsl_eigen_nonsymm_alloc(size_t n)
Allocate a nonsymmetric eigenvalue workspace for matrices.
void gsl_eigen_nonsymm_free(gsl_eigen_nonsymm_workspace *w)
Free a workspace allocated by gsl_eigen_nonsymm_alloc.
gsl_eigen_nonsymmv_workspace * gsl_eigen_nonsymmv_alloc(size_t n)
Allocate a nonsymmetric eigenvalue/vector workspace for matrices.
gsl_complex gsl_linalg_complex_LU_det(const gsl_matrix_complex *LU, int signum)
Determinant from LU decomposition (complex).
void gsl_permutation_free(gsl_permutation *p)
Free a permutation allocated by gsl_permutation_alloc.
int gsl_linalg_LU_invert(const gsl_matrix *LU, const gsl_permutation *p, gsl_matrix *inverse)
Invert a matrix from its LU decomposition (real).
gsl_permutation * gsl_permutation_alloc(size_t n)
Allocate an identity permutation of size .
int gsl_linalg_complex_LU_decomp(gsl_matrix_complex *A, gsl_permutation *p, int *signum)
In-place LU decomposition with partial pivoting (complex).
int gsl_linalg_complex_LU_invert(const gsl_matrix_complex *LU, const gsl_permutation *p, gsl_matrix_complex *inverse)
Invert a matrix from its LU decomposition (complex).
double gsl_linalg_LU_det(const gsl_matrix *LU, int signum)
Determinant from LU decomposition (real).
int gsl_linalg_LU_decomp(gsl_matrix *A, gsl_permutation *p, int *signum)
In-place LU decomposition with partial pivoting (real).
gsl_matrix * gsl_matrix_alloc(size_t n1, size_t n2)
Allocate a zero-initialized real matrix of size .
void gsl_matrix_complex_transpose_memcpy(gsl_matrix_complex *dest, const gsl_matrix_complex *src)
Copy the transpose into dest (complex).
void gsl_matrix_free(gsl_matrix *m)
Free a matrix allocated by gsl_matrix_alloc.
void gsl_matrix_complex_memcpy(gsl_matrix_complex *dest, const gsl_matrix_complex *src)
Copy src into dest (complex matrices).
void gsl_matrix_transpose_memcpy(gsl_matrix *dest, const gsl_matrix *src)
Copy the transpose into dest.
void gsl_matrix_complex_free(gsl_matrix_complex *m)
Free a matrix allocated by gsl_matrix_complex_alloc.
gsl_matrix_complex * gsl_matrix_complex_alloc(size_t n1, size_t n2)
Allocate a zero-initialized complex matrix of size .
void gsl_matrix_memcpy(gsl_matrix *dest, const gsl_matrix *src)
Copy src into dest (real matrices).
void invert()
turns this matrix into its inverse
MVector< Tmplt > get_mvector(size_t column) const
size_t num_col() const
returns number of columns in the matrix
MVector< m_complex > eigenvalues() const
returns a vector of eigenvalues. Throws an exception if either this matrix is not square or the eigen...
void build_matrix(size_t i, size_t j)
MMatrix< Tmplt > & operator=(const MMatrix< Tmplt > &mm)
MMatrix< Tmplt > T() const
returns matrix transpose T (such that M(i,j) = T(j,i))
size_t num_row() const
returns number of rows in the matrix
std::pair< MVector< m_complex >, MMatrix< m_complex > > eigenvectors() const
MMatrix< Tmplt > inverse() const
returns matrix inverse leaving this matrix unchanged
MMatrix< Tmplt > sub(size_t min_row, size_t max_row, size_t min_col, size_t max_col) const
static MMatrix< Tmplt > Diagonal(size_t i, Tmplt diag_value, Tmplt off_diag_value)
Construct a square matrix filling on and off diagonal values.
Tmplt determinant() const
returns matrix determinant; throws an exception if matrix is not square
MMatrix()
default constructor makes an empty MMatrix of size (0,0)
Tmplt trace() const
returns sum of terms with row == column, even if matrix is not square
static gsl_vector * get_vector(const MVector< double > &m)
m_complex m_complex_build(double r, double i)
MMatrix< m_complex > complex(MMatrix< double > real)
template std::istream & operator>>(std::istream &in, MMatrix< double > &mat)
MMatrix< double > re(MMatrix< m_complex > mc)
std::ostream & operator<<(std::ostream &out, const Mesh::Iterator &it)
MMatrix< double > & operator*=(MMatrix< double > &m1, MMatrix< double > m2)
MMatrix< double > im(MMatrix< m_complex > mc)
Complex number stored as .
Workspace for nonsymmetric eigenvalue computation.
Workspace for nonsymmetric eigenvalues/eigenvectors.
Dense complex matrix in row-major storage.
Dense real matrix in row-major storage.
Permutation vector for LU decomposition.