36 #ifndef UBLASCUSTOMFUNCTIONS_HPP_
37 #define UBLASCUSTOMFUNCTIONS_HPP_
59 inline T
Determinant(
const boost::numeric::ublas::c_matrix<T, 1, 1>& rM)
61 using namespace boost::numeric::ublas;
73 T
Determinant(
const boost::numeric::ublas::c_matrix<T,2,2>& rM)
75 using namespace boost::numeric::ublas;
77 return rM(0,0)*rM(1,1) - rM(1,0)*rM(0,1);
87 T
Determinant(
const boost::numeric::ublas::c_matrix<T, 3, 3>& rM)
89 using namespace boost::numeric::ublas;
91 return rM(0,0) * (rM(1,1)*rM(2,2) - rM(1,2)*rM(2,1))
92 - rM(0,1) * (rM(1,0)*rM(2,2) - rM(1,2)*rM(2,0))
93 + rM(0,2) * (rM(1,0)*rM(2,1) - rM(1,1)*rM(2,0));
108 using namespace boost::numeric::ublas;
109 c_matrix<T,2,2> product = prod(trans(rM), rM);
123 using namespace boost::numeric::ublas;
124 return std::sqrt(rM(0,0)*rM(0,0) + rM(1,0)*rM(1,0) + rM(2,0)*rM(2,0));
137 using namespace boost::numeric::ublas;
138 return std::sqrt(rM(0,0) * rM(0,0) + rM(1,0) * rM(1,0));
189 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 1, 1>& rM,
const unsigned missrow,
const unsigned misscol)
191 using namespace boost::numeric::ublas;
193 assert(missrow == 0);
194 assert(misscol == 0);
207 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 2, 2>& rM,
const unsigned missrow,
const unsigned misscol)
209 using namespace boost::numeric::ublas;
214 unsigned row = (missrow==1) ? 0 : 1;
215 unsigned col = (misscol==1) ? 0 : 1;
228 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 3, 3>& rM,
const unsigned missrow,
const unsigned misscol)
230 using namespace boost::numeric::ublas;
235 unsigned lorow = (missrow==0) ? 1 : 0;
236 unsigned hirow = (missrow==2) ? 1 : 2;
237 unsigned locol = (misscol==0) ? 1 : 0;
238 unsigned hicol = (misscol==2) ? 1 : 2;
239 return rM(lorow,locol)*rM(hirow,hicol) - rM(lorow,hicol)*rM(hirow,locol);
253 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 3, 2>& rM,
const unsigned missrow,
const unsigned misscol)
255 using namespace boost::numeric::ublas;
260 unsigned lorow = (missrow==0) ? 1 : 0;
261 unsigned hirow = (missrow==2) ? 1 : 2;
262 unsigned locol = (misscol==0) ? 1 : 0;
263 unsigned hicol = (misscol==2) ? 1 : 2;
264 return rM(lorow,locol)*rM(hirow,hicol) - rM(lorow,hicol)*rM(hirow,locol);
276 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 3, 1>& rM,
const unsigned missrow,
const unsigned misscol)
278 using namespace boost::numeric::ublas;
283 unsigned lorow = (missrow==0) ? 1 : 0;
284 unsigned hirow = (missrow==2) ? 1 : 2;
285 unsigned locol = (misscol==0) ? 1 : 0;
286 unsigned hicol = (misscol==2) ? 1 : 2;
287 return rM(lorow,locol)*rM(hirow,hicol) - rM(lorow,hicol)*rM(hirow,locol);
299 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 2, 1>& rM,
const unsigned missrow,
const unsigned misscol)
301 using namespace boost::numeric::ublas;
306 unsigned row = (missrow==1) ? 0 : 1;
307 unsigned col = (misscol==1) ? 0 : 1;
313 #else //#if defined(__xlC__)
323 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 3, 0>& rM,
const unsigned missrow,
const unsigned misscol)
337 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 2, 0>& rM,
const unsigned missrow,
const unsigned misscol)
351 T
SubDeterminant(
const boost::numeric::ublas::c_matrix<T, 1, 0>& rM,
const unsigned missrow,
const unsigned misscol)
355 #endif //#if defined(__xlC__)
367 boost::numeric::ublas::c_matrix<T, 1, 1>
Inverse(
const boost::numeric::ublas::c_matrix<T, 1, 1>& rM)
369 using namespace boost::numeric::ublas;
371 c_matrix<T,1,1> inverse;
373 assert(fabs(det) > DBL_EPSILON);
374 inverse(0,0) = 1.0/det;
386 boost::numeric::ublas::c_matrix<T, 2, 2>
Inverse(
const boost::numeric::ublas::c_matrix<T, 2, 2>& rM)
388 using namespace boost::numeric::ublas;
390 c_matrix<T, 2, 2> inverse;
393 assert( fabs(det) > DBL_EPSILON );
394 inverse(0,0) = rM(1,1)/det;
395 inverse(0,1) = -rM(0,1)/det;
396 inverse(1,0) = -rM(1,0)/det;
397 inverse(1,1) = rM(0,0)/det;
409 boost::numeric::ublas::c_matrix<T, 3, 3>
Inverse(
const boost::numeric::ublas::c_matrix<T, 3, 3>& rM)
411 using namespace boost::numeric::ublas;
413 c_matrix<T, 3, 3> inverse;
415 assert(fabs(det) > DBL_EPSILON);
417 inverse(0,0) = (rM(1,1)*rM(2,2) - rM(1,2)*rM(2,1))/det;
418 inverse(1,0) = -(rM(1,0)*rM(2,2) - rM(1,2)*rM(2,0))/det;
419 inverse(2,0) = (rM(1,0)*rM(2,1) - rM(1,1)*rM(2,0))/det;
420 inverse(0,1) = -(rM(0,1)*rM(2,2) - rM(0,2)*rM(2,1))/det;
421 inverse(1,1) = (rM(0,0)*rM(2,2) - rM(0,2)*rM(2,0))/det;
422 inverse(2,1) = -(rM(0,0)*rM(2,1) - rM(0,1)*rM(2,0))/det;
423 inverse(0,2) = (rM(0,1)*rM(1,2) - rM(0,2)*rM(1,1))/det;
424 inverse(1,2) = -(rM(0,0)*rM(1,2) - rM(0,2)*rM(1,0))/det;
425 inverse(2,2) = (rM(0,0)*rM(1,1) - rM(0,1)*rM(1,0))/det;
440 boost::numeric::ublas::c_matrix<T, 2, 3>
Inverse(
const boost::numeric::ublas::c_matrix<T, 3, 2>& rM)
442 using namespace boost::numeric::ublas;
444 c_matrix<T, 2, 3> inverse;
450 T a = rM(0,0)*rM(0,0) + rM(1,0)*rM(1,0) + rM(2,0)*rM(2,0);
451 T b = rM(0,0)*rM(0,1) + rM(1,0)*rM(1,1) + rM(2,0)*rM(2,1);
453 T d = rM(0,1)*rM(0,1) + rM(1,1)*rM(1,1) + rM(2,1)*rM(2,1);
462 inverse(0,0) = a_inv*rM(0,0) + b_inv*rM(0,1);
463 inverse(1,0) = c_inv*rM(0,0) + d_inv*rM(0,1);
464 inverse(0,1) = a_inv*rM(1,0) + b_inv*rM(1,1);
465 inverse(1,1) = c_inv*rM(1,0) + d_inv*rM(1,1);
466 inverse(0,2) = a_inv*rM(2,0) + b_inv*rM(2,1);
467 inverse(1,2) = c_inv*rM(2,0) + d_inv*rM(2,1);
480 boost::numeric::ublas::c_matrix<T, 1, 2>
Inverse(
const boost::numeric::ublas::c_matrix<T, 2, 1>& rM)
482 using namespace boost::numeric::ublas;
484 c_matrix<T, 1, 2> inverse;
487 inverse(0,0) = rM(0,0)/det/det;
488 inverse(0,1) = rM(1,0)/det/det;
501 boost::numeric::ublas::c_matrix<T, 1, 3>
Inverse(
const boost::numeric::ublas::c_matrix<T, 3, 1>& rM)
503 using namespace boost::numeric::ublas;
505 c_matrix<T, 1, 3> inverse;
508 inverse(0,0) = rM(0,0)/det/det;
509 inverse(0,1) = rM(1,0)/det/det;
510 inverse(0,2) = rM(2,0)/det/det;
524 inline T
Trace(
const c_matrix<T, 1, 1>& rM)
536 inline T
Trace(
const c_matrix<T, 2, 2>& rM)
538 return rM(0,0) + rM(1,1);
548 inline T
Trace(
const c_matrix<T, 3, 3>& rM)
550 return rM(0,0) + rM(1,1) + rM(2,2);
560 inline T
Trace(
const c_matrix<T, 4, 4>& rM)
562 return rM(0,0) + rM(1,1) + rM(2,2) + rM(3,3);
578 return rM(0,0)*rM(1,1) + rM(1,1)*rM(2,2) + rM(2,2)*rM(0,0)
579 - rM(1,0)*rM(1,0) - rM(2,1)*rM(2,1) - rM(2,0)*rM(2,0);
626 c_vector<T, 1>
VectorProduct(
const c_vector<T, 1>& rA,
const c_vector<T, 1>& rB)
639 c_vector<T, 2>
VectorProduct(
const c_vector<T, 2>& rA,
const c_vector<T, 2>& rB)
652 c_vector<T, 3>
VectorProduct(
const c_vector<T, 3>& rA,
const c_vector<T, 3>& rB)
655 c_vector<T, 3> result;
657 result(0) = rA(1)*rB(2) - rA(2)*rB(1);
658 result(1) = rA(2)*rB(0) - rA(0)*rB(2);
659 result(2) = rA(0)*rB(1) - rA(1)*rB(0);
T SecondInvariant(const c_matrix< T, 3, 3 > &rM)
boost::numeric::ublas::c_matrix< T, 1, 1 > Inverse(const boost::numeric::ublas::c_matrix< T, 1, 1 > &rM)
c_vector< double, 3 > CalculateEigenvectorForSmallestNonzeroEigenvalue(c_matrix< double, 3, 3 > &rA)
T Trace(const c_matrix< T, 1, 1 > &rM)
c_vector< T, 1 > VectorProduct(const c_vector< T, 1 > &rA, const c_vector< T, 1 > &rB)
T Determinant(const boost::numeric::ublas::c_matrix< T, 1, 1 > &rM)
c_vector< double, 1 > Create_c_vector(double x)
T SubDeterminant(const boost::numeric::ublas::c_matrix< T, 1, 1 > &rM, const unsigned missrow, const unsigned misscol)
double CalculateMaxEigenpair(c_matrix< double, 3, 3 > &rA, c_vector< double, 3 > &rEigenvector)