File: singular_value_decomposition.cpp

package info (click to toggle)
cgal 4.9-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 85,584 kB
  • sloc: cpp: 640,841; ansic: 140,696; sh: 708; fortran: 131; makefile: 114; python: 92
file content (37 lines) | stat: -rw-r--r-- 800 bytes parent folder | download
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
#ifdef CGAL_EIGEN3_ENABLED
#include <CGAL/Eigen_matrix.h>
#include <CGAL/Eigen_vector.h>
#include <CGAL/Eigen_svd.h>
typedef CGAL::Eigen_svd Svd;
#endif

typedef Svd::FT     FT;
typedef Svd::Vector Eigen_vector;
typedef Svd::Matrix Eigen_matrix;

int main(void)
{
  std::size_t degree = 3;
  
  Eigen_vector B (degree);
  Eigen_matrix M (degree, degree);

  // Fill B and M with random numbers
  for (std::size_t i = 0; i < degree; ++ i)
    {
      B.set (i, rand());
      for (std::size_t j = 0; j < degree; ++ j)
	M.set (i, j, rand());
    }

  // Solve MX=B
  std::cout << Svd::solve(M, B) << std::endl;

  // Print result
  std::cout << "Solution of SVD = [ ";
  for (std::size_t i = 0; i < degree; ++ i)
    std::cout << B.vector()[i] << " ";
  std::cout << "]" << std::endl;
  
  return 0;
}