TAPs 0.7.7.3
sp_mathematics.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 SP_Mathematics.h
00003 
00004 Include all mathematics constants and functions
00005 
00006 Sukitti Punak   (11/02/2003)
00007 Latest Update   (07/14/2007)
00008 ******************************************************************************/
00009 #ifndef SP_MATHEMATICS_H
00010 #define SP_MATHEMATICS_H
00011 
00012 #include <iostream>
00013 #include <cmath>
00014 using std::cout;
00015 using std::cerr;
00016 using std::endl;
00017 //using namespace std;
00018 
00019 #include <complex>
00020 
00021 #include "SP_MatrixOperations.h"
00022 #include "SPT_Matrix3x3.h"
00023 
00024 namespace SP_Maths {
00025 
00026     // CONSTANT VALUES  *******************************************************
00027     const double PI = 3.141592654;
00028     //-------------------------------------------------------------------------
00029     // FN:  CrossProduct()
00030     // DESC:    Find C = A^B
00031     void CrossProduct( const double A[3], const double B[3], double C[3] );
00032     //-------------------------------------------------------------------------
00033     // FN:  DotProduct()
00034     // DESC:    Return double = A*B
00035     double DotProduct( const double A[3], const double B[3] );
00036     //-------------------------------------------------------------------------
00037     // FN:  FindAnEigenVector()
00038     // DESC:    Find an eigen vector of a 3x3 symmetric matrix
00039     void FindAnEigenVector( 
00040         double &m11,    double &m12,    double &m13,
00041                         double &m22,    double &m23,
00042                                         double &m33,    // I/P: 3x3 Symmetric Matrix
00043         double l1,      // O/P: eigen value
00044         double v1[3]    // O/P: eigen vector
00045     );
00046     //-------------------------------------------------------------------------
00047     // FN:  FindOrthogonalVectors()
00048     // DESC:    Find other two vectors (oB and oC) that are orthogonal to iA
00049     void FindOrthogonalVectors( const double iA[3], double oB[3], double oC[3] );
00050     //-------------------------------------------------------------------------
00051     void rootsOfCubicPolynomialCodeGeneratedByMaple(    
00052         double a, double b, double c, double d , 
00053         std::complex<double> &r1, 
00054         std::complex<double> &r2, 
00055         std::complex<double> &r3 
00056     );
00057     //-------------------------------------------------------------------------
00058     // FN:  rootsOfCubicPolynomial()  *****************************************
00059     // DESC:    Find all three roots of a cubic polynomial in this form;
00060     //          a*x^3 + b*x^2 + c*x + d = 0;
00061     //          The formula is adapted from "Mathematical Handbook of Formulas and Tables"
00062     // I/P:  a, b, c, and d
00063     // O/P:  r1, r2, and r3     ( r1 is the real root)
00064     //       r2 and r3 are only the real parts of the other two roots
00065     double rootsOfCubicPolynomial(  
00066         double a, double b, double c, double d , 
00067         //double &r1, double &r2, double &r3 )
00068         std::complex<double> &r1, 
00069         std::complex<double> &r2, 
00070         std::complex<double> &r3 
00071     );
00072     //-------------------------------------------------------------------------
00073     // Overloaded Function
00074     double rootsOfCubicPolynomial(  double a, double b, double c, double d , 
00075                                     double &r1, double &r2, double &r3 );
00076     //-------------------------------------------------------------------------
00077     // MARK: FIX IT!!!!!!!!!!!!!!!!
00078     // FN:  rootOfCubicPolynomial()  ******************************************
00079     // DESC:    Find all three roots of a cubic polynomial in this form;
00080     //          a*x^3 + b*x^2 + c*x + d = 0;
00081     // The formula is adapted from "Mathematical Handbook of Formulas and Tables"
00082     // I/P:  a, b, c, d, and rootNo
00083     // O/P:  a double value of the rootNo (1, 2, or 3)
00084     //       r1 is the real root
00085     //       r2 and r3 are only the real parts of the other two roots
00086     double rootOfCubicPolynomial( double a, double b, double c, double d , int rootNo );
00087     //-------------------------------------------------------------------------
00088     // FN:  eigenValsOf3by3SymMatrix()      ***********************************
00089     // DESC:    Find eigen values of a 3x3 symmetric matrix
00090     // I/P:  (double) m11, m12, m13, m22, m23, m33
00091     // O/P:  (double) lamda1, lamda2, lamda3
00092     double eigenValsOf3by3SymMatrix(    
00093         double m11, double m12, double m13, 
00094                     double m22, double m23, 
00095                                 double m33, 
00096         double &lamda1, double &lamda2, double &lamda3 
00097     );
00098     //-------------------------------------------------------------------------
00099     // FN:  eigenValsOf3by3SymMatrixSmith1961()     ***************************
00100     // DESC:    Find eigen values of a 3x3 symmetric matrix
00101     // I/P:  (double) m11, m12, m13, m22, m23, m33
00102     // O/P:  (double) lamda1, lamda2, lamda3
00103     double eigenValsOf3by3SymMatrixSmith1961(   
00104         double m11, double m12, double m13, 
00105                     double m22, double m23, 
00106                                 double m33, 
00107         double &lamda1,     double &lamda2,     double &lamda3 
00108     );
00109     //-------------------------------------------------------------------------
00110     // FN:  eigenValsAndVecsOf3by3SymMatrix()  ********************************
00111     // DESC:    Find eigen vectors of a 3x3 symmetric matrix which has all real eigen values
00112     // I/P:  (double) m11, m12, m13, m22, m23, m33
00113     // O/P:  (double) lamda1, lamda2, lamda3
00114     void eigenValsAndVecsOf3by3SymMatrix(   
00115         double m11, double m12, double m13, 
00116                     double m22, double m23, 
00117                                 double m33, 
00118         double &l1, double &l2, double &l3,
00119         double v1[3], double v2[3], double v3[3] 
00120     );
00121     //-------------------------------------------------------------------------
00122     // FN:  eigenValsAndVecsOf3by3SymMatrixUsingQRFactor()  *******************
00123     // DESC:    Find eigen vectors of a 3x3 symmetric matrix which has all real eigen values
00124     // I/P:  (double) m11, m12, m13, m22, m23, m33
00125     // O/P:  (double) lamda1, lamda2, lamda3
00126     void eigenValsAndVecsOf3by3SymMatrixUsingQRFactor(  
00127         double m11, double m12, double m13, 
00128                     double m22, double m23, 
00129                                 double m33, 
00130         double &l1, double &l2, double &l3,
00131         double v1[3], double v2[3], double v3[3] 
00132     );
00133     //-------------------------------------------------------------------------
00134     // FN:  RootFindingByNewtonRaphsonMethod()  *******************************
00135     // ADAPTED FROM:    "Numerical Recipes in C: The Art of Scientific Computing" (1988)
00136     //                  by W. H. Press, B. P. Flannery, S. A. Teukolsky, and W. T. Vetterling
00137     // DESC:  Using the Newton-Raphson method to find the root of a function known to lie in the 
00138     //        interval (x1,x2).  The root rtnewt will be refined until its accuracy is known within 
00139     //        +/-xacc.  funcd is a user-supplied routine that provides both the funciton value and 
00140     //        the first derivative of the function at the point x.
00141     double RootFindingByNewtonRaphsonMethod( 
00142         void (*funcd)( double x, double *fx, double *dfx ), // A user-supplied routine that provides both the function value and the first derivative of the function at the point x.
00143         double x1, double x2,                               // The root of a function must lies in the interval (x1,x2).
00144         double xacc                                         // The root will be refined until its accuracy is known within +/-xacc.
00145     );
00146     //--------------------------------------------------------------------------------------------
00147 } // END: namespace SP_Maths
00148 //-----------------------------------------------------------------------------
00149 // Include definition if TAPs_USE_EXPORT is not defined
00150 #if !defined( TAPs_USE_EXPORT )
00151     #include "SP_Mathematics.cpp"
00152 #endif
00153 //-----------------------------------------------------------------------------
00154 #endif // #ifndef SP_MATHEMATICS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines