Simbody
3.4 (development)
|
00001 #ifndef SimTK_LINEAR_ALGEBRA_H_ 00002 #define SimTK_LINEAR_ALGEBRA_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKmath * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK biosimulation toolkit originating from * 00008 * Simbios, the NIH National Center for Physics-Based Simulation of * 00009 * Biological Structures at Stanford, funded under the NIH Roadmap for * 00010 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2006-12 Stanford University and the Authors. * 00013 * Authors: Jack Middleton * 00014 * Contributors: Michael Sherman * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00033 #include "SimTKcommon.h" 00034 #include "simmath/internal/common.h" 00035 00036 00037 namespace SimTK { 00038 00039 // default for reciprocal of the condition number 00040 // TODO: sherm 080128 I changed this from 0.01 to a more reasonable 00041 // value but it is still wrong because the default should depend 00042 // on the matrix size, something like max(m,n)*eps^(7/8) where 00043 // eps is machine precision for float or double as appropriate. 00044 static const double DefaultRecpCondition = 1e-12; 00045 00049 class SimTK_SIMMATH_EXPORT Factor { 00050 public: 00051 00052 Factor() {} 00054 template <class ELT> Factor( Matrix_<ELT> m ); 00056 template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const; 00058 template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const; 00059 00060 }; // class Factor 00061 00062 class FactorLURepBase; 00063 00067 class SimTK_SIMMATH_EXPORT FactorLU: public Factor { 00068 public: 00069 00070 ~FactorLU(); 00071 00072 FactorLU(); 00073 FactorLU( const FactorLU& c ); 00074 FactorLU& operator=(const FactorLU& rhs); 00075 00076 template <class ELT> FactorLU( const Matrix_<ELT>& m ); 00078 template <class ELT> void factor( const Matrix_<ELT>& m ); 00080 template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const; 00082 template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const; 00083 00085 template <class ELT> void getL( Matrix_<ELT>& l ) const; 00087 template <class ELT> void getU( Matrix_<ELT>& u ) const; 00089 template < class ELT > void inverse( Matrix_<ELT>& m ) const; 00090 00092 bool isSingular() const; 00094 int getSingularIndex() const; 00095 00096 00097 protected: 00098 class FactorLURepBase *rep; 00099 00100 }; // class FactorLU 00101 00102 00103 class FactorQTZRepBase; 00107 class SimTK_SIMMATH_EXPORT FactorQTZ: public Factor { 00108 public: 00109 00110 ~FactorQTZ(); 00111 00112 FactorQTZ(); 00113 FactorQTZ( const FactorQTZ& c ); 00114 FactorQTZ& operator=(const FactorQTZ& rhs); 00116 template <typename ELT> FactorQTZ( const Matrix_<ELT>& m); 00118 template <typename ELT> FactorQTZ( const Matrix_<ELT>& m, double rcond ); 00120 template <typename ELT> FactorQTZ( const Matrix_<ELT>& m, float rcond ); 00122 template <typename ELT> void factor( const Matrix_<ELT>& m); 00124 template <typename ELT> void factor( const Matrix_<ELT>& m, float rcond ); 00126 template <typename ELT> void factor( const Matrix_<ELT>& m, double rcond ); 00128 template <typename ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const; 00130 template <typename ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const; 00131 00132 template < class ELT > void inverse( Matrix_<ELT>& m ) const; 00133 00135 int getRank() const; 00137 double getRCondEstimate() const; 00138 // void setRank(int rank); TBD 00139 00140 protected: 00141 class FactorQTZRepBase *rep; 00142 }; // class FactorQTZ 00146 class SimTK_SIMMATH_EXPORT Eigen { 00147 public: 00148 00149 ~Eigen(); 00150 00151 Eigen(); 00152 Eigen( const Eigen& c ); 00153 Eigen& operator=(const Eigen& rhs); 00154 00156 template <class ELT> Eigen( const Matrix_<ELT>& m ); 00158 template <class ELT> void factor( const Matrix_<ELT>& m ); 00160 template <class VAL, class VEC> void getAllEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors); 00162 template <class T> void getAllEigenValues( Vector_<T>& values); 00163 00165 template <class VAL, class VEC> void getFewEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors, int ilow, int ihi); 00167 template <class T> void getFewEigenVectors( Matrix_<T>& vectors, int ilow, int ihi ); 00169 template <class T> void getFewEigenValues( Vector_<T>& values, int ilow, int ihi ); 00170 00172 template <class VAL, class VEC> void getFewEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors, typename CNT<VAL>::TReal rlow, typename CNT<VAL>::TReal rhi); 00174 template <class T> void getFewEigenVectors( Matrix_<T>& vectors, typename CNT<T>::TReal rlow, typename CNT<T>::TReal rhi ); 00176 template <class T> void getFewEigenValues( Vector_<T>& values, typename CNT<T>::TReal rlow, typename CNT<T>::TReal rhi ); 00177 00178 00179 protected: 00180 class EigenRepBase *rep; 00181 00182 }; // class Eigen 00186 class SimTK_SIMMATH_EXPORT FactorSVD: public Factor { 00187 public: 00188 00189 ~FactorSVD(); 00191 FactorSVD(); 00193 FactorSVD( const FactorSVD& c ); 00195 FactorSVD& operator=(const FactorSVD& rhs); 00196 00198 template < class ELT > FactorSVD( const Matrix_<ELT>& m ); 00201 template < class ELT > FactorSVD( const Matrix_<ELT>& m, float rcond ); 00204 template < class ELT > FactorSVD( const Matrix_<ELT>& m, double rcond ); 00206 template < class ELT > void factor( const Matrix_<ELT>& m ); 00209 template < class ELT > void factor( const Matrix_<ELT>& m, float rcond ); 00212 template < class ELT > void factor( const Matrix_<ELT>& m, double rcond ); 00213 00215 template < class T > void getSingularValuesAndVectors( Vector_<typename CNT<T>::TReal>& values, 00216 Matrix_<T>& leftVectors, Matrix_<T>& rightVectors ); 00218 template < class T > void getSingularValues( Vector_<T>& values); 00219 00221 int getRank(); 00223 template < class ELT > void inverse( Matrix_<ELT>& m ); 00225 template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ); 00228 template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ); 00229 00230 protected: 00231 class FactorSVDRepBase *rep; 00232 00233 }; // class FactorSVD 00234 00235 } // namespace SimTK 00236 00237 #endif //SimTK_LINEAR_ALGEBRA_H_