Simbody 3.9
Loading...
Searching...
No Matches
LinearAlgebra.h
Go to the documentation of this file.
1#ifndef SimTK_LINEAR_ALGEBRA_H_
2#define SimTK_LINEAR_ALGEBRA_H_
3
4/* -------------------------------------------------------------------------- *
5 * Simbody(tm): SimTKmath *
6 * -------------------------------------------------------------------------- *
7 * This is part of the SimTK biosimulation toolkit originating from *
8 * Simbios, the NIH National Center for Physics-Based Simulation of *
9 * Biological Structures at Stanford, funded under the NIH Roadmap for *
10 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11 * *
12 * Portions copyright (c) 2006-12 Stanford University and the Authors. *
13 * Authors: Jack Middleton *
14 * Contributors: Michael Sherman *
15 * *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17 * not use this file except in compliance with the License. You may obtain a *
18 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19 * *
20 * Unless required by applicable law or agreed to in writing, software *
21 * distributed under the License is distributed on an "AS IS" BASIS, *
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23 * See the License for the specific language governing permissions and *
24 * limitations under the License. *
25 * -------------------------------------------------------------------------- */
26
33#include "SimTKcommon.h"
35
36
37namespace SimTK {
38
39// default for reciprocal of the condition number
40// TODO: sherm 080128 I changed this from 0.01 to a more reasonable
41// value but it is still wrong because the default should depend
42// on the matrix size, something like max(m,n)*eps^(7/8) where
43// eps is machine precision for float or double as appropriate.
44static const double DefaultRecpCondition = 1e-12;
45
50public:
51
52 Factor() {}
54 template <class ELT> Factor( Matrix_<ELT> m );
56 template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const;
58 template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const;
59
60}; // class Factor
61
62class FactorLURepBase;
67 public:
68
70
72 FactorLU( const FactorLU& c );
73 FactorLU( FactorLU&& ) noexcept;
74 FactorLU& operator=(const FactorLU& rhs);
75 FactorLU& operator=(FactorLU&& rhs) noexcept;
76
77 template <class ELT> FactorLU( const Matrix_<ELT>& m );
79 template <class ELT> void factor( const Matrix_<ELT>& m );
81 template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const;
83 template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const;
84
86 template <class ELT> void getL( Matrix_<ELT>& l ) const;
88 template <class ELT> void getU( Matrix_<ELT>& u ) const;
90 template < class ELT > void inverse( Matrix_<ELT>& m ) const;
91
93 bool isSingular() const;
95 int getSingularIndex() const;
96
97
98 protected:
99 ClonePtr<FactorLURepBase> rep;
100
101}; // class FactorLU
102
103class FactorLLTRepBase;
108 public:
110
113 FactorLLT(FactorLLT&& c) noexcept;
115 FactorLLT& operator=(FactorLLT&& rhs) noexcept;
116
117 template <class ELT>
120 template <class ELT>
121 void factor(const Matrix_<ELT>& m);
123 template <class ELT>
124 void solve(const Vector_<ELT>& b, Vector_<ELT>& x) const;
126 template <class ELT>
127 void solve(const Matrix_<ELT>& b, Matrix_<ELT>& x) const;
128
130 template <class ELT>
131 void inverse(Matrix_<ELT>& m) const;
132
134 template <class ELT>
135 void getL(Matrix_<ELT>& l) const;
136
137 protected:
139
140}; // class FactorLLT
141
142class FactorQTZRepBase;
147 public:
148
150
152 FactorQTZ( const FactorQTZ& c );
153 FactorQTZ( FactorQTZ&& c ) noexcept;
155 FactorQTZ& operator=(FactorQTZ&& rhs) noexcept;
156
158 template <typename ELT> FactorQTZ( const Matrix_<ELT>& m);
160 template <typename ELT> FactorQTZ( const Matrix_<ELT>& m, double rcond );
162 template <typename ELT> FactorQTZ( const Matrix_<ELT>& m, float rcond );
164 template <typename ELT> void factor( const Matrix_<ELT>& m);
166 template <typename ELT> void factor( const Matrix_<ELT>& m, float rcond );
168 template <typename ELT> void factor( const Matrix_<ELT>& m, double rcond );
170 template <typename ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x ) const;
172 template <typename ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x ) const;
173
174 template < class ELT > void inverse( Matrix_<ELT>& m ) const;
175
177 int getRank() const;
179 double getRCondEstimate() const;
180// void setRank(int rank); TBD
181
182 protected:
184}; // class FactorQTZ
185
186class EigenRepBase;
191 public:
192
194
196 Eigen( const Eigen& c );
197 Eigen( Eigen&& c ) noexcept;
198 Eigen& operator=(const Eigen& rhs);
199 Eigen& operator=(Eigen&& rhs) noexcept;
200
202 template <class ELT> Eigen( const Matrix_<ELT>& m );
204 template <class ELT> void factor( const Matrix_<ELT>& m );
206 template <class VAL, class VEC> void getAllEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors);
208 template <class T> void getAllEigenValues( Vector_<T>& values);
209
211 template <class VAL, class VEC> void getFewEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors, int ilow, int ihi);
213 template <class T> void getFewEigenVectors( Matrix_<T>& vectors, int ilow, int ihi );
215 template <class T> void getFewEigenValues( Vector_<T>& values, int ilow, int ihi );
216
218 template <class VAL, class VEC> void getFewEigenValuesAndVectors( Vector_<VAL>& values, Matrix_<VEC>& vectors, typename CNT<VAL>::TReal rlow, typename CNT<VAL>::TReal rhi);
220 template <class T> void getFewEigenVectors( Matrix_<T>& vectors, typename CNT<T>::TReal rlow, typename CNT<T>::TReal rhi );
222 template <class T> void getFewEigenValues( Vector_<T>& values, typename CNT<T>::TReal rlow, typename CNT<T>::TReal rhi );
223
224
225 protected:
227
228}; // class Eigen
229
230class FactorSVDRepBase;
235 public:
236
241 FactorSVD( const FactorSVD& c );
243 FactorSVD( FactorSVD&& ) noexcept;
245 FactorSVD& operator=(const FactorSVD& rhs);
247 FactorSVD& operator=(FactorSVD&&) noexcept;
248
250 template < class ELT > FactorSVD( const Matrix_<ELT>& m );
253 template < class ELT > FactorSVD( const Matrix_<ELT>& m, float rcond );
256 template < class ELT > FactorSVD( const Matrix_<ELT>& m, double rcond );
258 template < class ELT > void factor( const Matrix_<ELT>& m );
261 template < class ELT > void factor( const Matrix_<ELT>& m, float rcond );
264 template < class ELT > void factor( const Matrix_<ELT>& m, double rcond );
265
267 template < class T > void getSingularValuesAndVectors( Vector_<typename CNT<T>::TReal>& values,
268 Matrix_<T>& leftVectors, Matrix_<T>& rightVectors );
270 template < class T > void getSingularValues( Vector_<T>& values);
271
273 int getRank();
275 template < class ELT > void inverse( Matrix_<ELT>& m );
277 template <class ELT> void solve( const Vector_<ELT>& b, Vector_<ELT>& x );
280 template <class ELT> void solve( const Matrix_<ELT>& b, Matrix_<ELT>& x );
281
282 protected:
283 ClonePtr<FactorSVDRepBase> rep;
284
285}; // class FactorSVD
286
287} // namespace SimTK
288
289#endif //SimTK_LINEAR_ALGEBRA_H_
Includes internal headers providing declarations for the basic SimTK Core classes,...
This is the header file that every Simmath compilation unit should include first.
#define SimTK_SIMMATH_EXPORT
Definition SimTKmath/include/simmath/internal/common.h:64
Specialized information about Composite Numerical Types which allows us to define appropriate templat...
Definition CompositeNumericalTypes.h:136
K::TReal TReal
Definition CompositeNumericalTypes.h:141
Smart pointer with deep copy semantics.
Definition ClonePtr.h:55
Class to compute Eigen values and Eigen vectors of a matrix.
Definition LinearAlgebra.h:190
ClonePtr< EigenRepBase > rep
Definition LinearAlgebra.h:226
Eigen & operator=(Eigen &&rhs) noexcept
Eigen & operator=(const Eigen &rhs)
void getAllEigenValues(Vector_< T > &values)
get all the eigen values of a matrix
void getFewEigenVectors(Matrix_< T > &vectors, int ilow, int ihi)
get a few eigen vectors of a symmetric matrix which are within a range of indices
Eigen(const Eigen &c)
Eigen(Eigen &&c) noexcept
void getFewEigenValues(Vector_< T > &values, typename CNT< T >::TReal rlow, typename CNT< T >::TReal rhi)
get a few eigen values of a symmetric matrix which are within a range of eigen values
void factor(const Matrix_< ELT > &m)
supply matrix which eigen values will be computed for
void getFewEigenValuesAndVectors(Vector_< VAL > &values, Matrix_< VEC > &vectors, int ilow, int ihi)
get a few eigen values and eigen vectors of a symmetric matrix which are within a range of indices
Eigen(const Matrix_< ELT > &m)
create a default eigen class
void getFewEigenValuesAndVectors(Vector_< VAL > &values, Matrix_< VEC > &vectors, typename CNT< VAL >::TReal rlow, typename CNT< VAL >::TReal rhi)
get a few eigen values and eigen vectors of a symmetric matrix which are within a range of eigen valu...
void getFewEigenVectors(Matrix_< T > &vectors, typename CNT< T >::TReal rlow, typename CNT< T >::TReal rhi)
get a few eigen vectors of a symmetric matrix which are within a range of eigen values
void getFewEigenValues(Vector_< T > &values, int ilow, int ihi)
get a few eigen values of a symmetric matrix which are within a range of indices
void getAllEigenValuesAndVectors(Vector_< VAL > &values, Matrix_< VEC > &vectors)
get all the eigen values and eigen vectors of a matrix
Class for performing LLT (Cholesky) matrix factorizations.
Definition LinearAlgebra.h:107
void factor(const Matrix_< ELT > &m)
factors a matrix
FactorLLT(const FactorLLT &c)
FactorLLT & operator=(FactorLLT &&rhs) noexcept
ClonePtr< FactorLLTRepBase > rep
Definition LinearAlgebra.h:138
FactorLLT(const Matrix_< ELT > &m)
void getL(Matrix_< ELT > &l) const
returns the lower triangle of an LLT factorization
void inverse(Matrix_< ELT > &m) const
returns the inverse of a matrix using an LLT (Cholesky) factorization
FactorLLT & operator=(const FactorLLT &rhs)
FactorLLT(FactorLLT &&c) noexcept
void solve(const Vector_< ELT > &b, Vector_< ELT > &x) const
solves a single right hand side
void solve(const Matrix_< ELT > &b, Matrix_< ELT > &x) const
solves multiple right hand sides
Class for performing LU matrix factorizations.
Definition LinearAlgebra.h:66
FactorLU(const FactorLU &c)
FactorLU(FactorLU &&) noexcept
Class to perform a QTZ (linear least squares) factorization.
Definition LinearAlgebra.h:146
void solve(const Vector_< ELT > &b, Vector_< ELT > &x) const
solve for a vector x given a right hand side vector b
void factor(const Matrix_< ELT > &m, double rcond)
do QTZ factorization of a matrix for a given reciprocal condition number
FactorQTZ(const Matrix_< ELT > &m)
do QTZ factorization of a matrix
ClonePtr< FactorQTZRepBase > rep
Definition LinearAlgebra.h:183
FactorQTZ(FactorQTZ &&c) noexcept
FactorQTZ & operator=(const FactorQTZ &rhs)
void factor(const Matrix_< ELT > &m, float rcond)
do QTZ factorization of a matrix for a given reciprocal condition number
FactorQTZ(const Matrix_< ELT > &m, double rcond)
do QTZ factorization of a matrix for a given reciprocal condition number
double getRCondEstimate() const
returns the actual reciprocal condition number at this rank
FactorQTZ & operator=(FactorQTZ &&rhs) noexcept
void factor(const Matrix_< ELT > &m)
do QTZ factorization of a matrix
FactorQTZ(const Matrix_< ELT > &m, float rcond)
do QTZ factorization of a matrix for a given reciprocal condition number
FactorQTZ(const FactorQTZ &c)
void inverse(Matrix_< ELT > &m) const
void solve(const Matrix_< ELT > &b, Matrix_< ELT > &x) const
solve for an array of vectors given multiple right hand sides
int getRank() const
returns the rank of the matrix
Class to compute a singular value decomposition of a matrix.
Definition LinearAlgebra.h:234
FactorSVD(const FactorSVD &c)
copy constructor
FactorSVD(FactorSVD &&) noexcept
move constructor
FactorSVD()
default constructor
Base class for the various matrix factorizations.
Definition LinearAlgebra.h:49
void solve(const Vector_< ELT > &b, Vector_< ELT > &x) const
solves a single right hand side using a factorization
Factor()
Definition LinearAlgebra.h:52
void solve(const Matrix_< ELT > &b, Matrix_< ELT > &x) const
solves multiple right hand sides using a factorization
Factor(Matrix_< ELT > m)
creates an factorization of a matrix
This is the matrix class intended to appear in user code for large, variable size matrices.
Definition Matrix_.h:51
This is the vector class intended to appear in user code for large, variable size column vectors.
Definition Vector_.h:52
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37
static const double DefaultRecpCondition
Definition LinearAlgebra.h:44