21 #ifndef SYMMETRIC_MATRIX_2X2_IMPL_H 22 #define SYMMETRIC_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 GENERAL_MATRIX_1X2_H 37 #include "SheafSystem/general_matrix_1x2.h" 40 #ifndef GENERAL_MATRIX_2X1_H 41 #include "SheafSystem/general_matrix_2x1.h" 44 #ifndef GENERAL_MATRIX_2X2_H 45 #include "SheafSystem/general_matrix_2x2.h" 48 #ifndef SYMMETRIC_MATRIX_2X2_H 49 #include "SheafSystem/symmetric_matrix_2x2.h" 52 #ifndef GENERAL_MATRIX_2X3_H 53 #include "SheafSystem/general_matrix_2x3.h" 57 #include "SheafSystem/std_sstream.h" 61 #include "SheafSystem/std_cmath.h" 67 using namespace sheaf;
75 symmetric_matrix_2x2<T>::
82 T* lcomps =
const_cast<T*
>(components);
102 T* lcomps =
const_cast<T*
>(components);
115 template <
typename T>
132 template <
typename T>
149 template <
typename T>
166 template <
typename T>
173 require(nrow >= 0 && nrow < number_of_rows());
177 T* result = &components[row_index(nrow)];
188 template <
typename T>
195 require(nrow >= 0 && nrow < number_of_rows());
199 const T* result = &components[row_index(nrow)];
211 template <
typename T>
221 T* result = components;
233 template <
typename T>
235 operator
const T* ()
const 243 const T* result = components;
255 template <
typename T>
262 require(xrow >= 0 && xrow < number_of_rows());
266 int nrows = number_of_rows();
267 int result = (xrow*(2*nrows-1-xrow))/2;
273 ensure(result == (xrow*(2*number_of_rows()-1-xrow))/2);
281 template <
typename T>
293 result[0][0] = lm[0][0];
294 result[0][1] = lm[0][1];
295 result[1][0] = lm[0][1];
296 result[1][1] = lm[1][1];
300 ensure(unexecutable(
"result == *this"));
308 template <
typename T>
315 require(xrow >= 0 && xrow < number_of_rows());
343 template <
typename T>
350 require(xcolumn >= 0 && xcolumn < number_of_columns());
376 template <
typename T>
395 xresult[0][1] = -a01;
405 template <
typename T>
425 template <
typename T>
436 components[0] = xvalue;
437 components[1] = xvalue;
438 components[2] = xvalue;
442 ensure_for_all(i, 0, d(), components[i] == xvalue);
449 template <
typename T>
465 xresult = a00*a11 - a01*a10;
474 template <
typename T>
495 template <
typename T>
517 T c = a00*a11 - a01*a10;
525 T discriminant = b*b - 4.0*c;
527 if(discriminant < 0.0)
529 post_fatal_error_message(
"Matrix has 2 complex roots.");
532 T sqrt_discriminant =
sqrt(discriminant);
534 T lambda_0 = 0.5*(-b-sqrt_discriminant);
535 T lambda_1 = 0.5*(-b+sqrt_discriminant);
542 xresult[0][0] = (lambda_0 < lambda_1) ? lambda_0 : lambda_1;
545 xresult[1][1] = (lambda_1 < lambda_0) ? lambda_0 : lambda_1;
550 ensure(unexecutable(
"for_all i, 0, 2, xresult[i][i] == real number"));
557 template <
typename T>
567 diagonalization(result);
572 ensure(unexecutable(
"for_all i, 0, 2, result[i][i] == real number"));
580 template <
typename T>
593 xresult[0][1] = zero;
604 template <
typename T>
627 template <
typename T>
647 if(determinant == 0.0)
649 post_fatal_error_message(
"No inverse; determinant is zero.");
663 template <
typename T>
683 template <
typename T>
694 bool result = (lm[0][1]==0.0);
705 template <
typename T>
716 bool result = is_diagonal() && (lm[0][0]==1.0) && (lm[1][1]==1.0);
727 template <
typename T>
745 bool result = (a00 > 0) && (a11 > 0) && (ldet > 0);
756 template <
typename T>
767 xresult.
components[0] = xscalar*components[0];
768 xresult.
components[1] = xscalar*components[1];
769 xresult.
components[2] = xscalar*components[2];
782 template <
typename T>
803 template <
typename T>
822 T b00 = xother[0][0];
823 T b10 = xother[1][0];
825 xresult[0][0] = a00*b00 + a01*b10;
826 xresult[1][0] = a10*b00 + a11*b10;
835 template <
typename T>
855 template <
typename T>
874 T b00 = xother[0][0];
875 T b01 = xother[0][1];
877 T b11 = xother[1][1];
879 xresult[0][0] = a00*b00 + a01*b10;
880 xresult[0][1] = a00*b01 + a01*b11;
881 xresult[1][0] = a10*b00 + a11*b10;
882 xresult[1][1] = a10*b01 + a11*b11;
891 template <
typename T>
911 template <
typename T>
930 T b00 = xother[0][0];
931 T b01 = xother[0][1];
932 T b10 = xother[1][0];
933 T b11 = xother[1][1];
935 xresult[0][0] = a00*b00 + a01*b10;
936 xresult[0][1] = a00*b01 + a01*b11;
937 xresult[1][0] = a10*b00 + a11*b10;
938 xresult[1][1] = a10*b01 + a11*b11;
947 template <
typename T>
967 template <
typename T>
986 T b00 = xother[0][0];
987 T b01 = xother[0][1];
988 T b02 = xother[0][2];
990 T b10 = xother[1][0];
991 T b11 = xother[1][1];
992 T b12 = xother[1][2];
994 xresult[0][0] = a00*b00 + a01*b10;
995 xresult[0][1] = a00*b01 + a01*b11;
996 xresult[0][2] = a00*b02 + a01*b12;
998 xresult[1][0] = a10*b00 + a11*b10;
999 xresult[1][1] = a10*b01 + a11*b11;
1000 xresult[1][2] = a10*b02 + a11*b12;
1009 template <
typename T>
1029 template <
typename T>
1042 xresult = lm[0][0] + lm[1][1];
1050 template <
typename T>
1071 template <
typename T>
1092 for(
int i=0; i<ld; ++i)
1104 template <
typename T>
1127 #ifndef DOXYGEN_SKIP_IMPLEMENTATIONS 1130 template <
typename T>
1131 std::ostream& operator<<(std::ostream& xos, const symmetric_matrix_2x2<T>& xm)
1140 xos <<
" " << xm[0][0] <<
" " << xm[0][1] << std::endl;
1141 xos <<
" " << xm[0][1] <<
" " << xm[1][1] << std::endl;
1150 #endif // ifndef DOXYGEN_SKIP_IMPLEMENTATIONS 1157 #endif // SYMMETRIC_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).
symmetric_matrix_2x2< T > inverse() const
The inverse of the matrix (auto-allocated).
T components[2]
Linear storage array.
symmetric_matrix_2x2< T > diagonalization() const
The diagonalization of the matrix (auto-allocated).
bool is_positive_definite() const
True if this matrix is positive definite.
T trace() const
The trace of the matrix (auto-allocated).
symmetric_matrix_2x2< T > adjoint() const
The adjoint of the matrix (auto-allocated).
Row dofs type for class st2_e2.
static int d()
Dimension of the underlying elements.
T determinant() const
The determinant of the matrix (auto-allocated).
static int number_of_rows()
The number of rows.
General matrix with 1 row and 2 columns.
General matrix with 2 rows and 2 columns.
static int number_of_columns()
The number of columns.
T components[2]
Linear storage array.
void trace(const S0 &x0, SR &xresult, bool xauto_access)
general_matrix_2x1< T > column(int xcolumn) const
A 2x1 matrix containing the elements or column xcolumn.
Symmetric matrix with 2 rows and 2 columns.
General matrix with 2 rows and 1 column.
symmetric_matrix_2x2< T > identity() const
The identity matrix (auto-allocated).
symmetric_matrix_2x2< T > transpose() const
The transpose of the matrix (auto-allocated).
void determinant(const S0 &x0, SR &xresult, bool xauto_access)
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.
void assign(const T &xscalar)
Assign all elements of this matrix to the value xvalue.
bool is_identity() const
True if this is an identity matrix.
bool is_diagonal() const
True if this matrix is diagonal.
T components[3]
Linear storage array.
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).
void multiply(const T &xscalar, symmetric_matrix_2x2< T > &xresult) const
This matrix multiplied by a scalar (pre-allocated).
T * operator[](int xrow)
Pointer to the first element in row xrow of this matrix. Facilitates accessing elements via matrix[i]...
Row dofs type for class met_e2.
int row_index(int xrow) const
Index for row xrow in the linear storage array.