Chemical Data Processing Library C++ API - Version 1.1.1
SVBackSubstitution.hpp
Go to the documentation of this file.
1 /*
2  * SVBackSubstitution.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_MATH_SVBACKSUBSTITUTION_HPP
30 #define CDPL_MATH_SVBACKSUBSTITUTION_HPP
31 
32 #include "CDPL/Math/Vector.hpp"
33 #include "CDPL/Math/Matrix.hpp"
34 
35 
36 namespace CDPL
37 {
38 
39  namespace Math
40  {
41 
65  template <typename M1, typename V1, typename M2, typename V2, typename V3>
66  void svBackSubstitution(const M1& u, const V1& w, const M2& v, const V2& b, V3& x);
67  } // namespace Math
68 } // namespace CDPL
69 
70 
71 // Implementation
72 
73 template <typename M1, typename V1, typename M2, typename V2, typename V3>
74 void CDPL::Math::svBackSubstitution(const M1& u, const V1& w, const M2& v, const V2& b, V3& x)
75 {
76  typedef typename V3::value_type T;
77 
78  typename M1::size_type n = u.size2();
79 
80  Vector<T> tmp(n);
81 
82  for (typename M1::size_type j = 0; j < n; j++) { // Calculate trans(U) * B
83  T s = 0;
84 
85  if (w(j) != 0) // Nonzero result only if w(j) is nonzero
86  s = inner_prod(column(u, j), b) / w(j);
87 
88  tmp(j) = s;
89  }
90 
91  x = prod(v, tmp);
92 }
93 
94 #endif // CDPL_MATH_SVBACKSUBSTITUTION_HPP
CDPL::Math::Vector< T >
CDPL::Math::column
MatrixColumn< M > column(MatrixExpression< M > &e, typename MatrixColumn< M >::SizeType j)
Definition: MatrixProxy.hpp:730
CDPL::Biomol::PDBFormatVersion::V3
const unsigned int V3
Specifies the PDB format version V3.
Definition: PDBFormatVersion.hpp:59
CDPL::Math::prod
Matrix1VectorBinaryTraits< E1, E2, MatrixVectorProduct< E1, E2 > >::ResultType prod(const MatrixExpression< E1 > &e1, const VectorExpression< E2 > &e2)
Definition: MatrixExpression.hpp:833
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Chem::CIPDescriptor::s
const unsigned int s
Specifies that the stereocenter has s configuration.
Definition: CIPDescriptor.hpp:81
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Math::svBackSubstitution
void svBackSubstitution(const M1 &u, const V1 &w, const M2 &v, const V2 &b, V3 &x)
Solves for a vector where is given by its Singular Value Decomposition [WSVD].
Definition: SVBackSubstitution.hpp:74
Matrix.hpp
Definition of matrix data types.
CDPL::Biomol::PDBFormatVersion::V2
const unsigned int V2
Specifies the PDB format version V2.
Definition: PDBFormatVersion.hpp:54
Vector.hpp
Definition of vector data types.