CPPLapack
 All Classes Files Functions Variables Friends Pages
Functions
dgematrix_small-specialized.hpp File Reference

Go to the source code of this file.

Functions

dgemat1 inv (const dgemat1 &A)
 
double det (const dgemat2 &A)
 
dgemat2 inv (const dgemat2 &A)
 
dgemat2 rotate (const dgemat2 &m, const double &theta)
 
dgemat2 t2m (const double &theta)
 
double det (const dgemat3 &A)
 
double II (const dgemat3 &A)
 
dgemat3 inv (const dgemat3 &A)
 
dgemat3 rotate (const dgemat3 &m, const dquater &q)
 
dquater m2q (const dgemat3 &m)
 
double det (const dgemat4 &A)
 
dgemat4 inv (const dgemat4 &A)
 

Function Documentation

dgemat1 inv ( const dgemat1 &  A)
inline

calculate inverse

Definition at line 3 of file dgematrix_small-specialized.hpp.

4 {CPPL_VERBOSE_REPORT;
5  dgemat1 Ainv;
6  Ainv(0,0) =1./A(0,0);
7  return Ainv;
8 }
double det ( const dgemat2 &  A)
inline

calculate determinant

Definition at line 22 of file dgematrix_small-specialized.hpp.

Referenced by inv().

23 {CPPL_VERBOSE_REPORT;
24  return A(0,0)*A(1,1)-A(0,1)*A(1,0);
25 }
dgemat2 inv ( const dgemat2 &  A)
inline

calculate inverse

Definition at line 29 of file dgematrix_small-specialized.hpp.

References det().

30 {CPPL_VERBOSE_REPORT;
31  const double Adet( det(A) );
32  dgemat2 Ainv;
33  Ainv(0,0)= A(1,1)/Adet; Ainv(0,1)=-A(0,1)/Adet;
34  Ainv(1,0)=-A(1,0)/Adet; Ainv(1,1)= A(0,0)/Adet;
35  return Ainv;
36 }
double det(const dgemat2 &A)
dgemat2 rotate ( const dgemat2 &  m,
const double &  theta 
)
inline

return rotated tensor

Definition at line 40 of file dgematrix_small-specialized.hpp.

41 {CPPL_VERBOSE_REPORT;
42  //dgemat2 R(t2m(theta)); return R*m*t(R);//too slow
43  double c(std::cos(theta)), s(std::sin(theta));
44  double cc(c*c), cs(c*s), ss(s*s);
45  dgemat2 mat;
46  mat(0,0) =m(0,0)*cc -(m(0,1)+m(1,0))*cs +m(1,1)*ss;
47  mat(0,1) =m(0,1)*cc +(m(0,0)-m(1,1))*cs -m(1,0)*ss;
48  mat(1,0) =m(1,0)*cc +(m(0,0)-m(1,1))*cs -m(0,1)*ss;
49  mat(1,1) =m(1,1)*cc +(m(0,1)+m(1,0))*cs +m(0,0)*ss;
50  return mat;
51 }
dgemat2 t2m ( const double &  theta)
inline

convert theta to 2x2 rotational matrix

Definition at line 55 of file dgematrix_small-specialized.hpp.

56 {CPPL_VERBOSE_REPORT;
57  dgemat2 R;
58  R(0,0)=std::cos(theta); R(0,1)=-std::sin(theta);
59  R(1,0)=std::sin(theta); R(1,1)= std::cos(theta);
60  return R;
61 }
double det ( const dgemat3 &  A)
inline

calculate determinant

Definition at line 75 of file dgematrix_small-specialized.hpp.

76 {CPPL_VERBOSE_REPORT;
77  return
78  +A(0,0)*A(1,1)*A(2,2) -A(0,0)*A(1,2)*A(2,1)
79  +A(0,1)*A(1,2)*A(2,0) -A(0,1)*A(1,0)*A(2,2)
80  +A(0,2)*A(1,0)*A(2,1) -A(0,2)*A(1,1)*A(2,0);
81 }
double II ( const dgemat3 &  A)
inline

calculate the 2nd invariant

Definition at line 85 of file dgematrix_small-specialized.hpp.

86 {CPPL_VERBOSE_REPORT;
87  return
88  +A(0,0)*A(1,1) +A(1,1)*A(2,2) +A(2,2)*A(0,0)
89  -A(0,1)*A(1,0) -A(1,2)*A(2,1) -A(2,0)*A(0,2);
90 }
dgemat3 inv ( const dgemat3 &  A)
inline

calculate inverse

Definition at line 94 of file dgematrix_small-specialized.hpp.

References det().

95 {CPPL_VERBOSE_REPORT;
96  const double Adet( det(A) );
97  dgemat3 Ainv;
98  Ainv(0,0) =(A(1,1)*A(2,2)-A(1,2)*A(2,1))/Adet;
99  Ainv(0,1) =(A(0,2)*A(2,1)-A(0,1)*A(2,2))/Adet;
100  Ainv(0,2) =(A(0,1)*A(1,2)-A(0,2)*A(1,1))/Adet;
101  Ainv(1,0) =(A(1,2)*A(2,0)-A(1,0)*A(2,2))/Adet;
102  Ainv(1,1) =(A(0,0)*A(2,2)-A(0,2)*A(2,0))/Adet;
103  Ainv(1,2) =(A(0,2)*A(1,0)-A(0,0)*A(1,2))/Adet;
104  Ainv(2,0) =(A(1,0)*A(2,1)-A(1,1)*A(2,0))/Adet;
105  Ainv(2,1) =(A(0,1)*A(2,0)-A(0,0)*A(2,1))/Adet;
106  Ainv(2,2) =(A(0,0)*A(1,1)-A(0,1)*A(1,0))/Adet;
107  return Ainv;
108 }
double det(const dgemat2 &A)
dgemat3 rotate ( const dgemat3 &  m,
const dquater &  q 
)
inline

rotate 3D matrix by quaternion

Definition at line 112 of file dgematrix_small-specialized.hpp.

References q2m(), and t().

113 {CPPL_VERBOSE_REPORT;
114  dgemat3 R(q2m(q));
115  return R*m*t(R);
116 }
dgemat3 q2m(const dquater &q)
drovector t(const _dcovector &covec)
dquater m2q ( const dgemat3 &  m)
inline

convert 3D rotational matrix to quaternion

Definition at line 120 of file dgematrix_small-specialized.hpp.

References t(), and vt2q().

121 {CPPL_VERBOSE_REPORT;
122  dcovec3 v( m(2,1)-m(1,2), m(0,2)-m(2,0), m(1,0)-m(0,1) );
123  double t( std::acos(0.5*(m(0,0)+m(1,1)+m(2,2)-1.)) );
124  return vt2q(v,t);
125 }
dquater vt2q(const dcovec3 &v, const double &theta)
drovector t(const _dcovector &covec)
double det ( const dgemat4 &  A)
inline

calculate determinant

Definition at line 139 of file dgematrix_small-specialized.hpp.

140 {CPPL_VERBOSE_REPORT;
141  return
142  ((A(0,0)*A(1,1)-A(0,1)*A(1,0))*A(2,2)+(A(0,2)*A(1,0)-A(0,0)*A(1,2))*A(2,1)+(A(0,1)*A(1,2)-A(0,2)*A(1,1))*A(2,0))*A(3,3)
143  +((A(0,1)*A(1,0)-A(0,0)*A(1,1))*A(2,3)+(A(0,0)*A(1,3)-A(0,3)*A(1,0))*A(2,1)+(A(0,3)*A(1,1)-A(0,1)*A(1,3))*A(2,0))*A(3,2)
144  +((A(0,0)*A(1,2)-A(0,2)*A(1,0))*A(2,3)+(A(0,3)*A(1,0)-A(0,0)*A(1,3))*A(2,2)+(A(0,2)*A(1,3)-A(0,3)*A(1,2))*A(2,0))*A(3,1)
145  +((A(0,2)*A(1,1)-A(0,1)*A(1,2))*A(2,3)+(A(0,1)*A(1,3)-A(0,3)*A(1,1))*A(2,2)+(A(0,3)*A(1,2)-A(0,2)*A(1,3))*A(2,1))*A(3,0);
146 }
dgemat4 inv ( const dgemat4 &  A)
inline

calculate inverse

Definition at line 150 of file dgematrix_small-specialized.hpp.

References det().

151 {CPPL_VERBOSE_REPORT;
152  const double Adet =det(A);
153 
154  dgemat4 Ainv;
155  Ainv(0,0) =(A(1,1)*A(2,2)-A(1,2)*A(2,1))*A(3,3)+(A(1,3)*A(2,1)-A(1,1)*A(2,3))*A(3,2)+(A(1,2)*A(2,3)-A(1,3)*A(2,2))*A(3,1);
156  Ainv(0,1) =(A(0,2)*A(2,1)-A(0,1)*A(2,2))*A(3,3)+(A(0,1)*A(2,3)-A(0,3)*A(2,1))*A(3,2)+(A(0,3)*A(2,2)-A(0,2)*A(2,3))*A(3,1);
157  Ainv(0,2) =(A(0,1)*A(1,2)-A(0,2)*A(1,1))*A(3,3)+(A(0,3)*A(1,1)-A(0,1)*A(1,3))*A(3,2)+(A(0,2)*A(1,3)-A(0,3)*A(1,2))*A(3,1);
158  Ainv(0,3) =(A(0,2)*A(1,1)-A(0,1)*A(1,2))*A(2,3)+(A(0,1)*A(1,3)-A(0,3)*A(1,1))*A(2,2)+(A(0,3)*A(1,2)-A(0,2)*A(1,3))*A(2,1);
159  Ainv(1,0) =(A(1,2)*A(2,0)-A(1,0)*A(2,2))*A(3,3)+(A(1,0)*A(2,3)-A(1,3)*A(2,0))*A(3,2)+(A(1,3)*A(2,2)-A(1,2)*A(2,3))*A(3,0);
160  Ainv(1,1) =(A(0,0)*A(2,2)-A(0,2)*A(2,0))*A(3,3)+(A(0,3)*A(2,0)-A(0,0)*A(2,3))*A(3,2)+(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