Changeset 4286
- Timestamp:
- Jan 30, 2023, 3:08:38 AM (8 weeks ago)
- Location:
- trunk/yat/utility
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/Matrix.cc
r4207 r4286 260 260 assert(A.rows() == A.columns()); 261 261 SVD svd(A); 262 // A = U S V'263 262 svd.decompose(); 264 265 // result = A^-1 = V * S^-1 * U' 266 267 DiagonalMatrix D(A.rows(), A.columns()); 268 // If eigenvalue is zero, A is not invertable, perhaps that should 269 // trigger an exception 270 for (size_t i=0; i<D.rows(); ++i) 271 D(i) = 1.0 / svd.s()(i); 272 273 result = svd.V() * D * transpose(svd.U()); 274 263 svd.inverse(result); 275 264 assert(result.columns() == result.rows()); 276 265 assert(result.rows() == A.rows()); -
trunk/yat/utility/SVD.cc
r4207 r4286 30 30 #include "SVD.h" 31 31 32 #include "DiagonalMatrix.h" 32 33 #include "Exception.h" 33 34 #include "Vector.h" … … 109 110 110 111 112 void SVD::inverse(Matrix& result) const 113 { 114 assert(U_.rows()==U_.columns() && "input matrix must be square"); 115 // A = U S V' 116 117 // result = A^-1 = V * S^-1 * U' 118 119 DiagonalMatrix D(s_.size(), s_.size()); 120 // If eigenvalue is zero, A is not invertable, perhaps that should 121 // trigger an exception 122 for (size_t i=0; i<D.rows(); ++i) 123 D(i) = 1.0 / s_(i); 124 125 result = V_ * D * transpose(U_); 126 } 127 128 111 129 const Vector& SVD::s(void) const 112 130 { -
trunk/yat/utility/SVD.h
r4207 r4286 101 101 102 102 /** 103 Calculate the inverse of the Matrix provided in the 104 constructor. Behaviour is undefined if the input matrix is not 105 square. 106 107 \since New in yat 0.21 108 109 \see inverse_svd(const MatrixBase&, Matrix&) 110 */ 111 void inverse(Matrix& result) const; 112 113 /** 103 114 \brief Access to the s vector. 104 115
Note: See TracChangeset
for help on using the changeset viewer.