Changeset 20895b for molecuilder/src/helpers.cpp
- Timestamp:
- Nov 4, 2009, 5:34:05 PM (16 years ago)
- Children:
- 5f1d021
- Parents:
- c1b76e
- File:
-
- 1 edited
-
molecuilder/src/helpers.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/helpers.cpp
rc1b76e r20895b 133 133 * \return allocated NDIM*NDIM array with the symmetric matrix 134 134 */ 135 double * ReturnFullMatrixforSymmetric( double *symm)135 double * ReturnFullMatrixforSymmetric(const double * const symm) 136 136 { 137 137 double *matrix = Malloc<double>(NDIM * NDIM, "molecule::ReturnFullMatrixforSymmetric: *matrix"); … … 148 148 }; 149 149 150 /** Calculate the inverse of a 3x3 matrix. 151 * \param *matrix NDIM_NDIM array 152 */ 153 double * InverseMatrix( const double * const A) 154 { 155 double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B"); 156 double detA = RDET3(A); 157 double detAReci; 158 159 for (int i=0;i<NDIM*NDIM;++i) 160 B[i] = 0.; 161 // calculate the inverse B 162 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular 163 detAReci = 1./detA; 164 B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11 165 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12 166 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13 167 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21 168 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22 169 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23 170 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31 171 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32 172 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 173 } 174 return B; 175 }; 176 177 /** hard-coded determinant of a 3x3 matrix. 178 * \param a[9] matrix 179 * \return \f$det(a)\f$ 180 */ 181 double RDET3(const double a[NDIM*NDIM]) 182 { 183 return ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]); 184 }; 185 186 /** hard-coded determinant of a 2x2 matrix. 187 * \param a[4] matrix 188 * \return \f$det(a)\f$ 189 */ 190 double RDET2(const double a[4]) 191 { 192 return ((a[0])*(a[3])-(a[1])*(a[2])); 193 }; 194 195 /** hard-coded determinant of a 2x2 matrix. 196 * \param a0 (0,0) entry of matrix 197 * \param a1 (0,1) entry of matrix 198 * \param a2 (1,0) entry of matrix 199 * \param a3 (1,1) entry of matrix 200 * \return \f$det(a)\f$ 201 */ 202 double RDET2(const double a0, const double a1, const double a2, const double a3) 203 { 204 return ((a0)*(a3)-(a1)*(a2)); 205 }; 206 150 207 /** Comparison function for GSL heapsort on distances in two molecules. 151 208 * \param *a
Note:
See TracChangeset
for help on using the changeset viewer.
