![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsGenMath.hpp 00003 00004 Under TAPs namespace 00005 Defines a GenMath class for general math. 00006 All member functions and data members are static. 00007 00008 SUKITTI PUNAK (01/20/2006) 00009 UPDATE (02/01/2006) 00010 ******************************************************************************/ 00011 #ifndef TAPs_GEN_MATH_HPP 00012 #define TAPs_GEN_MATH_HPP 00013 00014 #include "TAPsMatrix.hpp" 00015 #include "TAPsMatrixp.hpp" 00016 #include "TAPsVector.hpp" 00017 //#include "TAPsVectorp.hpp" 00018 00019 #include <complex> 00020 00021 BEGIN_NAMESPACE_TAPs 00022 //============================================================================= 00023 template <typename T> 00024 class GenMath { 00025 public: 00026 //============================================================================= 00027 //========================================================================== 00028 // Root Finding Fns 00029 //========================================================================== 00030 //------------------------------------------------------------------------- 00031 // Root of second degree polynomial 00032 //------------------------------------------------------------------------- 00033 // FN: rootsOfQuadraticPolynomial() ************************************** 00034 // DESC: Find all three roots of a cubic polynomial in this form; 00035 // a*x^2 + b*x + c = 0 00036 //The formula is adapted from "Mathematical Handbook of Formulas and Tables" 00037 // I/P: a, b, and c 00038 // O/P: r1 and r2 00039 // (r1 and r2 may be real or complex conjugate of one another) 00040 static void RootsOfQuadraticPolynomial ( 00041 T a, T b, T c, // I/P: a*x^2 + b*x + c = 0 00042 std::complex<T> &r1, // O/P: root number one 00043 std::complex<T> &r2 ); // O/P: root number two 00044 //------------------------------------------------------------------------- 00045 //------------------------------------------------------------------------- 00046 // Root of third degree polynomial 00047 //------------------------------------------------------------------------- 00048 // FN: rootsOfCubicPolynomial() ****************************************** 00049 // DESC: Find all three roots of a cubic polynomial in this form; 00050 // a*x^3 + b*x^2 + c*x + d = 0 00051 //The formula is adapted from "Mathematical Handbook of Formulas and Tables" 00052 // I/P: a, b, c, and d 00053 // O/P: r1, r2, and r3 ( r1 is the real root) 00054 // (r2 and r3 may be real or complex conjugate of one another) 00055 static void RootsOfCubicPolynomial ( 00056 T a, T b, T c, T d, // I/P: a*x^3 + b*x^2 + c*x + d = 0 00057 std::complex<T> &r1, // O/P: root number one 00058 std::complex<T> &r2, // O/P: root number two 00059 std::complex<T> &r3 ); // O/P: root number three 00060 //------------------------------------------------------------------------- 00061 //========================================================================== 00062 00063 //========================================================================== 00064 // Matrix Fns 00065 //========================================================================== 00066 //------------------------------------------------------------------------- 00067 // FN: eigenValsAndVecsOf3by3SymMatrixUsingQRFactor() ********************* 00068 // DESC: Find eigen vectors of a 3x3 symmetric matrix which has all 00069 // real eigen values 00070 // I/P: (T) m11, m12, m13, m22, m23, m33 00071 // O/P: (T) lamda1, lamda2, lamda3 00072 // O/P: (T) v1[3], v2[3], v3[3] 00073 static void EigenValsAndVecsOf3by3SymMatrixUsingQRFactor ( 00074 T m11, T m12, T m13, // I/P: 00075 T m22, T m23, // I/P: 00076 T m33, // I/P: 00077 T &l1, T &l2, T &l3, // O/P: eigenvalues 00078 T v1[3], T v2[3], T v3[3], // O/P: eigenvectors 00079 T errThreshold = 10*Math<T>::EPSILON, // I/P: error threshold 00080 int times_limit = 256 // I/P: iteration limit 00081 ); 00082 //------------------------------------------------------------------------- 00083 // Member Fn: EigenValsByQRFactorization() ------------------------ 00084 // Desc: Find all eigen values of a real square matrix only. 00085 // I/P: A is a real square matrix. 00086 // I/P: (default = 6), times is the number of iterations. 00087 // O/P: (default = NULL), ptrO is a pointer to a matrix with will be the same 00088 // order as I/P Matrix, A. Its diagonal are the approximated eigen values. 00089 // Return: A column vector (n-by-1 matrix) contains all approximated eigenvalues. 00090 static Matrixp<T> EigenValsByQRFactorization ( 00091 const Matrixp<T> &A, // I/P 00092 int times, // Number of iterations 00093 Matrixp<T> *ptrO // O/P 00094 ); 00095 //------------------------------------------------------------------------- 00096 // FN: FindAnEigenVector() 00097 // DESC: Find an eigen vector of a 3x3 symmetric matrix 00098 static void FindAnEigenVector( 00099 T &m11, T &m12, T &m13, 00100 T &m22, T &m23, 00101 T &m33, // I/P: 3x3 Symmetric Matrix 00102 T l1, // O/P: eigen value 00103 T v1[3] // O/P: eigen vector 00104 ); 00105 //------------------------------------------------------------------------- 00106 // FN: FindOrthogonalVectors() 00107 // DESC: Find other two vectors (oB and oC) that are orthogonal to iA 00108 static void FindOrthogonalVectors( const T iA[3], T oB[3], T oC[3] ); 00109 //------------------------------------------------------------------------- 00110 // Member Fn: QRFactorization() 00111 // Desc: Find a QR Factorization of a real square matrix only. 00112 static bool QRFactorization( 00113 const Matrixp<T> &A, // I/P 00114 Matrixp<T> &Q, Matrixp<T> &R // O/P 00115 ); 00116 //------------------------------------------------------------------------- 00117 // Member Fn: HouseHolderMatrix() 00118 // Desc: Find a HouseHolder matrix of a real square matrix only. 00119 static Matrixp<T> HouseHolderMatrix( 00120 const Matrixp<T> &A, // I/P 00121 Matrixp<T> *ptrH, // O/P 00122 Matrixp<T> *ptrR // O/P 00123 ); 00124 //------------------------------------------------------------------------- 00125 //========================================================================== 00126 00127 //========================================================================== 00128 // Math Fns for array data, e.g. T b[]. For example dot product, etc. 00129 //========================================================================== 00130 //------------------------------------------------------------------------- 00131 // FN: CrossProduct3() 00132 // DESC: Find C = A^B 00133 inline static void CrossProduct3( const T A[3], const T B[3], T C[3] ); 00134 //------------------------------------------------------------------------- 00135 // FN: DotProduct3() 00136 // DESC: Return T = A[3]*B[3] 00137 inline static T DotProduct3( const T A[3], const T B[3] ); 00138 //------------------------------------------------------------------------- 00139 //========================================================================== 00140 }; // END CLASS Math 00141 //============================================================================= 00142 END_NAMESPACE_TAPs 00143 //----------------------------------------------------------------------------- 00144 // Include definition if TAPs_USE_EXPORT is not defined 00145 //#if !defined( TAPs_USE_EXPORT ) 00146 #include "TAPsGenMath.cpp" 00147 //#endif 00148 //----------------------------------------------------------------------------- 00149 #endif 00150 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00151 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8