21 #ifndef GENERAL_MATRIX_2X2_IMPL_H 22 #define GENERAL_MATRIX_2X2_IMPL_H 24 #ifndef SHEAF_DLL_SPEC_H 25 #include "SheafSystem/sheaf_dll_spec.h" 28 #ifndef ASSERT_CONTRACT_H 29 #include "SheafSystem/assert_contract.h" 32 #ifndef ERROR_MESSAGE_H 33 #include "SheafSystem/error_message.h" 36 #ifndef ANTISYMMETRIC_MATRIX_2X2_H 37 #include "SheafSystem/antisymmetric_matrix_2x2.h" 40 #ifndef GENERAL_MATRIX_1X2_H 41 #include "SheafSystem/general_matrix_1x2.h" 44 #ifndef GENERAL_MATRIX_2X1_H 45 #include "SheafSystem/general_matrix_2x1.h" 48 #ifndef GENERAL_MATRIX_2X2_H 49 #include "SheafSystem/general_matrix_2x2.h" 52 #ifndef GENERAL_MATRIX_2X3_H 53 #include "SheafSystem/general_matrix_2x3.h" 56 #ifndef SYMMETRIC_MATRIX_2X2_H 57 #include "SheafSystem/symmetric_matrix_2x2.h" 61 #include "SheafSystem/std_sstream.h" 65 #include "SheafSystem/std_cmath.h" 71 using namespace sheaf;
79 general_matrix_2x2<T>::
86 T* lcomps =
const_cast<T*
>(components);
107 T* lcomps =
const_cast<T*
>(components);
120 template <
typename T>
128 T* lcomps =
const_cast<T*
>(components);
142 template <
typename T>
159 template <
typename T>
176 template <
typename T>
193 template <
typename T>
200 require(xrow >= 0 && xrow < number_of_rows());
204 T* result = &components[row_index(xrow)];
215 template <
typename T>
222 require(xrow >= 0 && xrow < number_of_rows());
226 const T* result = &components[row_index(xrow)];
238 template <
typename T>
248 T* result = components;
260 template <
typename T>
262 operator
const T* ()
const 270 const T* result = components;
282 template <
typename T>
290 require(xrow >= 0 && xrow < number_of_rows());
294 int result = number_of_columns()*xrow;
298 ensure(result == number_of_columns()*xrow);
306 template <
typename T>
313 require(xrow >= 0 && xrow < number_of_rows());
319 int lindex = row_index(xrow);
332 template <
typename T>
339 require(xcolumn >= 0 && xcolumn < number_of_columns());
345 int lindex = xcolumn;
359 template <
typename T>
378 xresult[0][1] = -a01;
379 xresult[1][0] = -a10;
388 template <
typename T>
408 template <
typename T>
417 for(
int i=0; i<d(); ++i)
419 components[i] = xvalue;
424 ensure_for_all(i, 0, d(), components[i] == xvalue);
431 template <
typename T>
447 xresult = a00*a11 - a01*a10;
456 template <
typename T>
477 template <
typename T>
499 T c = a00*a11 - a01*a10;
507 T discriminant = b*b - 4.0*c;
509 if(discriminant < 0.0)
511 post_fatal_error_message(
"Matrix has 2 complex roots.");
514 T sqrt_discriminant =
sqrt(discriminant);
516 T lambda_0 = 0.5*(-b-sqrt_discriminant);
517 T lambda_1 = 0.5*(-b+sqrt_discriminant);
524 xresult[0][0] = (lambda_0 < lambda_1) ? lambda_0 : lambda_1;
527 xresult[1][1] = (lambda_1 < lambda_0) ? lambda_0 : lambda_1;
532 ensure(unexecutable(
"for_all i, 0, 2, xresult[i][i] == real number"));
539 template <
typename T>
549 diagonalization(result);
554 ensure(unexecutable(
"for_all i, 0, 2, result[i][i] == real number"));
562 template <
typename T>
575 xresult[0][1] = zero;
576 xresult[1][0] = zero;
587 template <
typename T>
610 template <
typename T>
630 if(determinant == 0.0)
632 post_fatal_error_message(
"No inverse; determinant is zero.");
646 template <
typename T>
666 template <
typename T>
677 bool result = (lm[0][0]==0.0) && (lm[1][1]==0.0) && (lm[1][0]==-lm[0][1]);
688 template <
typename T>
699 bool result = (lm[0][1]==0.0) && (lm[1][0]==0.0);
710 template <
typename T>
721 bool result = is_diagonal() && (lm[0][0]==1.0) && (lm[1][1]==1.0);
732 template <
typename T>
757 template <
typename T>
768 bool result = (lm[1][0]==lm[0][1]);
779 template <
typename T>
788 for(
int i=0; i<d(); ++i)
790 xresult.
components[i] = xscalar*components[i];
804 template <
typename T>
824 template <
typename T>
838 int nra = number_of_rows();
839 int nca = number_of_columns();
842 for(
int i=0; i<nra; ++i)
844 for(
int j=0; j<ncb; ++j)
848 for(
int k=0; k<nca; ++k)
850 sum += lm[i][k]*xother[k][j];
864 template <
typename T>
884 template <
typename T>
898 int nra = number_of_rows();
899 int nca = number_of_columns();
902 for(
int i=0; i<nra; ++i)
904 for(
int j=0; j<ncb; ++j)
908 for(
int k=0; k<nca; ++k)
910 sum += lm[i][k]*xother[k][j];
924 template <
typename T>
944 template <
typename T>
958 int nra = number_of_rows();
959 int nca = number_of_columns();
962 for(
int i=0; i<nra; ++i)
964 for(
int j=0; j<ncb; ++j)
968 for(
int k=0; k<nca; ++k)
970 sum += lm[i][k]*xother[k][j];
984 template <
typename T>
1004 template <
typename T>
1017 xresult = lm[0][0] + lm[1][1];
1025 template <
typename T>
1046 template <
typename T>
1057 xresult[0][0] = lm[0][0];
1058 xresult[0][1] = lm[1][0];
1059 xresult[1][0] = lm[0][1];
1060 xresult[1][1] = lm[1][1];
1069 template <
typename T>
1089 template <
typename T>
1102 xresult[0][1] = 2.0*lm[0][1];
1110 template <
typename T>
1120 antisymmetric_part(result);
1131 template <
typename T>
1144 xresult[0][0] = 2.0*lm[0][0];
1145 xresult[0][1] = lm[0][1] + lm[1][0];
1146 xresult[1][1] = 2.0*lm[1][1];
1154 template <
typename T>
1164 symmetric_part(result);
1177 #ifndef DOXYGEN_SKIP_IMPLEMENTATIONS 1180 template <
typename T>
1181 std::ostream& operator<<(std::ostream& xos, const general_matrix_2x2<T>& xm)
1187 xos <<
" " << xm[0][0] <<
" " << xm[0][1] << std::endl;
1188 xos <<
" " << xm[1][0] <<
" " << xm[1][1] << std::endl;
1197 #endif // ifndef DOXYGEN_SKIP_IMPLEMENTATIONS 1204 #endif // GENERAL_MATRIX_2X2_IMPL_H SHEAF_DLL_SPEC void sqrt(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute sqrt of x0 (sqrt(x0)) (pre-allocated version).
bool is_positive_definite() const
True if this matrix is positive definite.
T components[2]
Linear storage array.
bool is_identity() const
True if this is an identity matrix.
T trace() const
The trace of the matrix (auto-allocated).
void assign(const T &xvalue)
Assign all elements of this matrix to the value xvalue.
bool is_positive_definite() const
True if this matrix is positive definite.
static int number_of_columns()
The number of columns.
T * operator[](int xrow)
Pointer to the first element in row xrow of this matrix. Facilitates accessing elements via matrix[i]...
general_matrix_2x2< T > inverse() const
The inverse of the matrix (auto-allocated).
static int number_of_columns()
The number of columns.
general_matrix_2x2< T > transpose() const
The transpose of the matrix (auto-allocated).
symmetric_matrix_2x2< T > symmetric_part() const
The symmetric part of a this matrix (auto-allocated).
general_matrix_2x1< T > column(int xcolumn) const
A 2x1 matrix containing the elements or column xcolumn.
T components[4]
Linear storage array.
General matrix with 1 row and 2 columns.
General matrix with 2 rows and 2 columns.
T components[2]
Linear storage array.
general_matrix_2x2< T > adjoint() const
The adjoint of the matrix (auto-allocated).
Row dofs type for class gl2.
general_matrix_2x2< T > diagonalization() const
The diagonalization of the matrix (auto-allocated).
void trace(const S0 &x0, SR &xresult, bool xauto_access)
void multiply(const T &xscalar, general_matrix_2x2< T > &xresult) const
This matrix multiplied by a scalar (pre-allocated).
int row_index(int xrow) const
Index for row xrow in the linear storage array.
general_matrix_2x2< T > identity() const
The identity matrix (auto-allocated).
Symmetric matrix with 2 rows and 2 columns.
General matrix with 2 rows and 1 column.
antisymmetric_matrix_2x2< T > antisymmetric_part() const
The antisymmetric part of a this matrix (auto-allocated).
Antisymmetric matrix with 2 rows and 2 columns.
bool is_diagonal() const
True if this matrix is diagonal.
bool is_antisymmetric() const
True if this matrix is antisymmetric.
void determinant(const S0 &x0, SR &xresult, bool xauto_access)
T determinant() const
The determinant of the matrix (auto-allocated).
static int number_of_rows()
The number of rows.
general_matrix_1x2< T > row(int xrow) const
A 1x2 matrix containing the elements or row xrow.
Namespace for the sheaves component of the sheaf system.
General matrix with 2 rows and 3 columns.
static int d()
Dimension of the underlying elements.
static int number_of_columns()
The number of columns.
bool is_symmetric() const
True if this matrix is symmetric.
SHEAF_DLL_SPEC void multiply(const vd &x0, const vd_value_type &x1, vd &xresult, bool xauto_access)
Vector x0 multiplied by scalar x1 (pre-allocated version for persistent types).
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC void inverse(const gl2_lite &xlite, gl2_lite &xresult)
Inverse (pre-allocated version for volatile type).