File: singular_value_decomposition.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (37 lines) | stat: -rw-r--r-- 775 bytes parent folder | download | duplicates (5)
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;
}