Simbody

LinearAlgebra.h

Go to the documentation of this file.
00001 #ifndef SimTK_LINEAR_ALGEBRA_H_
00002 #define SimTK_LINEAR_ALGEBRA_H_
00003 /* -------------------------------------------------------------------------- *
00004  *                      SimTK Core: SimTK Simmath(tm)                         *
00005  * -------------------------------------------------------------------------- *
00006  * This is part of the SimTK Core biosimulation toolkit originating from      *
00007  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00008  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00009  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00010  *                                                                            *
00011  * Portions copyright (c) 2006-10 Stanford University and the Authors.        *
00012  * Authors: Jack Middleton                                                    *
00013  * Contributors: Michael Sherman                                              *
00014  *                                                                            *
00015  * Permission is hereby granted, free of charge, to any person obtaining a    *
00016  * copy of this software and associated documentation files (the "Software"), *
00017  * to deal in the Software without restriction, including without limitation  *
00018  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00019  * and/or sell copies of the Software, and to permit persons to whom the      *
00020  * Software is furnished to do so, subject to the following conditions:       *
00021  *                                                                            *
00022  * The above copyright notice and this permission notice shall be included in *
00023  * all copies or substantial portions of the Software.                        *
00024  *                                                                            *
00025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00026  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00027  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00028  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00029  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00030  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00031  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00032  * -------------------------------------------------------------------------- */
00033 
00034 
00041 #include "SimTKcommon.h"
00042 #include "simmath/internal/common.h"
00043 
00044 
00045 namespace SimTK {
00046 
00047 //  default for reciprocal of the condition number
00048 // TODO: sherm 080128 I changed this from 0.01 to a more reasonable
00049 // value but it is still wrong because the default should depend
00050 // on the matrix size, something like max(m,n)*eps^(7/8) where
00051 // eps is machine precision for float or double as appropriate.
00052 static const double DefaultRecpCondition = 1e-12;
00053 
00057 class SimTK_SIMMATH_EXPORT Factor {
00058 public:
00059 
00060   Factor() {}
00062   template <class ELT> Factor( Matrix_<ELT> m );
00064   template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const;
00066   template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const;
00067   
00068 }; // class Factor
00069 
00070 class FactorLURepBase;
00071 
00075 class SimTK_SIMMATH_EXPORT FactorLU: public Factor {
00076     public:
00077 
00078     ~FactorLU();
00079 
00080     FactorLU();
00081     FactorLU( const FactorLU& c );
00082     FactorLU& operator=(const FactorLU& rhs);
00083 
00084     template <class ELT> FactorLU( const Matrix_<ELT>& m );
00086     template <class ELT> void factor( const Matrix_<ELT>& m );
00088     template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const;
00090     template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const;
00091 
00093     template <class ELT> void getL( Matrix_<ELT>& l ) const;
00095     template <class ELT> void getU( Matrix_<ELT>& u ) const;
00097     template < class ELT > void inverse(  Matrix_<ELT>& m ) const;
00098 
00100     bool isSingular() const;
00102     int getSingularIndex() const;
00103 
00104 
00105     protected:
00106     class FactorLURepBase *rep;
00107 
00108 }; // class FactorLU
00109 
00110 
00111 class FactorQTZRepBase;
00115 class SimTK_SIMMATH_EXPORT FactorQTZ: public Factor {
00116     public:
00117 
00118     ~FactorQTZ();
00119 
00120     FactorQTZ();
00121     FactorQTZ( const FactorQTZ& c );
00122     FactorQTZ& operator=(const FactorQTZ& rhs);
00124     template <typename ELT> FactorQTZ( const Matrix_<ELT>& m);
00126     template <typename ELT> FactorQTZ( const Matrix_<ELT>& m, double rcond );
00128     template <typename ELT> FactorQTZ( const Matrix_<ELT>& m, float rcond );
00130     template <typename ELT> void factor( const Matrix_<ELT>& m);
00132     template <typename ELT> void factor( const Matrix_<ELT>& m, float rcond );
00134     template <typename ELT> void factor( const Matrix_<ELT>& m, double rcond );
00136     template <typename ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const;
00138     template <typename ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const;
00139 
00140     template < class ELT > void inverse(  Matrix_<ELT>& m ) const;
00141 
00143     int getRank() const;
00145     double getRCondEstimate() const;
00146 //    void setRank(int rank); TBD
00147 
00148     protected:
00149     class FactorQTZRepBase *rep;
00150 }; // class FactorQTZ
00154 class SimTK_SIMMATH_EXPORT Eigen {
00155     public:
00156 
00157     ~Eigen();
00158 
00159     Eigen();
00160     Eigen( const Eigen& c );
00161     Eigen& operator=(const Eigen& rhs);
00162 
00164     template <class ELT> Eigen( const Matrix_<ELT>& m );
00166     template <class ELT> void factor( const Matrix_<ELT>& m );
00168     template <class VAL, class VEC> void getAllEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors);
00170     template <class T> void getAllEigenValues( Vector_<T>& values);
00171 
00173     template <class VAL, class VEC> void getFewEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors, int ilow, int ihi);
00175     template <class T> void getFewEigenVectors( Matrix_<T>& vectors, int ilow, int ihi );
00177     template <class T> void getFewEigenValues( Vector_<T>& values, int ilow, int ihi );
00178 
00180     template <class VAL, class VEC> void getFewEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors, typename CNT<VAL>::TReal rlow, typename CNT<VAL>::TReal rhi);
00182     template <class T> void getFewEigenVectors( Matrix_<T>& vectors, typename CNT<T>::TReal rlow, typename CNT<T>::TReal rhi );
00184     template <class T> void getFewEigenValues( Vector_<T>& values, typename CNT<T>::TReal rlow, typename CNT<T>::TReal rhi );
00185 
00186      
00187     protected:
00188     class EigenRepBase *rep;
00189 
00190 }; // class Eigen
00194 class SimTK_SIMMATH_EXPORT FactorSVD: public Factor {
00195     public:
00196 
00197     ~FactorSVD();
00199     FactorSVD();
00201     FactorSVD( const FactorSVD& c );
00203     FactorSVD& operator=(const FactorSVD& rhs);
00204 
00206     template < class ELT > FactorSVD( const Matrix_<ELT>& m );
00209     template < class ELT > FactorSVD( const Matrix_<ELT>& m, float rcond );
00212     template < class ELT > FactorSVD( const Matrix_<ELT>& m, double rcond );
00214     template < class ELT > void factor( const Matrix_<ELT>& m );
00217     template < class ELT > void factor( const Matrix_<ELT>& m, float rcond );
00220     template < class ELT > void factor( const Matrix_<ELT>& m, double rcond );
00221 
00223     template < class T > void getSingularValuesAndVectors( Vector_<typename CNT<T>::TReal>& values, 
00224                               Matrix_<T>& leftVectors,  Matrix_<T>& rightVectors );
00226     template < class T > void getSingularValues( Vector_<T>& values);
00227 
00229     int getRank();
00231     template < class ELT > void inverse(  Matrix_<ELT>& m );
00233     template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x );
00236     template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x );
00237 
00238     protected:
00239     class FactorSVDRepBase *rep;
00240 
00241 }; // class FactorSVD
00242 
00243 } // namespace SimTK 
00244 
00245 #endif //SimTK_LINEAR_ALGEBRA_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines