-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVD.h
37 lines (31 loc) · 1.13 KB
/
SVD.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef MY_SVD_H
#define MY_SVD_H
#include <limits>
#include <vector>
#include "Matrix.h"
#include <cmath>
/** @brief In this namespace the singular value decomposition is implemented.
*/
namespace SVD
{
void decomposeMatrix (Matrix& U, std::vector<double>& S, Matrix& V); ///< computes the SV decomposition
void computeSymmetricEigenvectors(Matrix& U); ///< computes the Eigenvectors for a symmetric square Matrix with SVD
void solveLinearEquationSystem(Matrix& A, std::vector<double>& x, const std::vector<double>& b);
/** @brief returns the square of a value.
@param v values
@return squared value
*/
inline double sqr(const double v){ return v*v;}
/** @brief returns the hypotenuse of two values.
@details It is just the Euklidean distance but takes care for numerical underflow and overflow.
@param v1,v2 values
@return hypotenuse
*/
inline double hypotenuse(const double& v1, const double& v2)
{
const double a(std::abs(v1)), b(std::abs(v2));
return (a > b ? a*std::sqrt(1.0 + sqr(b / a)) :
(b == 0.0 ? 0.0 : b*std::sqrt(1.0 + sqr(a / b))));
}
};
#endif