• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////
2 //  Copyright 2018 John Maddock. Distributed under the Boost
3 //  Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
5 
6 //[eigen_eg
7 #include <iostream>
8 #include <boost/multiprecision/cpp_complex.hpp>
9 #include <boost/multiprecision/eigen.hpp>
10 #include <Eigen/Dense>
11 
main()12 int main()
13 {
14    using namespace Eigen;
15    typedef boost::multiprecision::cpp_complex_quad complex_type;
16    //
17    // We want to solve Ax = b for x,
18    // define A and b first:
19    //
20    Matrix<complex_type, 2, 2> A, b;
21    A << complex_type(2, 3), complex_type(-1, -2), complex_type(-1, -4), complex_type(3, 6);
22    b << 1, 2, 3, 1;
23    std::cout << "Here is the matrix A:\n" << A << std::endl;
24    std::cout << "Here is the right hand side b:\n" << b << std::endl;
25    //
26    // Solve for x:
27    //
28    Matrix<complex_type, 2, 2> x = A.fullPivHouseholderQr().solve(b);
29    std::cout << "The solution is:\n" << x << std::endl;
30    //
31    // Compute the error in the solution by using the norms of Ax - b and b:
32    //
33    complex_type::value_type relative_error = (A*x - b).norm() / b.norm();
34    std::cout << "The relative error is: " << relative_error << std::endl;
35    return 0;
36 }
37 //]
38 
39 /*
40 //[eigen_out
41 Here is the matrix A:
42 (2,3) (-1,-2)
43 (-1,-4)   (3,6)
44 Here is the right hand side b:
45 1 2
46 3 1
47 The solution is:
48 (0.6,-0.6)   (0.7,-0.7)
49 (0.64,-0.68) (0.58,-0.46)
50 The relative error is: 2.63132e-34
51 //]
52 */
53