19{
20
21 cout << "\n";
22 cout << "=== Matrix: Example linear solver ==================\n";
23 cout << "\n";
24
26
27 const double tol = 1.e-10;
28
29
30
31
38 B[ 0 ] = 5.;
39 B[ 1 ] = 11.;
40
41 std::cout << " Simple 2x2 (dense) system solved by native Gauss Jordan routine.\n";
43
44 try
45 {
46 small_system.solve();
47 }
48 catch ( const std::runtime_error &error )
49 {
50 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
51 return 1;
52 }
54 answer[ 0 ] = 1.0;
55 answer[ 1 ] = 2.0;
56 B.sub( answer );
57 if ( B.inf_norm() > tol )
58 {
59 std::cout << " Simple 2x2 system was not solved correctly\n";
60 std::cout << " residual vector's inf_norm = " << B.inf_norm() << "\n";
62 }
63 else
64 {
65 std::cout << " Simple 2x2 `dense' solver works.\n";
66 }
67
68
69
70
71
74 Ac( 0, 0 ) = 1.;
75 Ac( 0, 1 ) = 2.;
76 Ac( 1, 0 ) = 3.;
77 Ac( 1, 1 ) = 4.;
78 Bc[ 0 ] = 5.;
79 Bc[ 1 ] = 11.;
80
81 std::cout << " Simple 2x2 (dense) complex system solved by native Gauss Jordan routine.\n";
83
84 try
85 {
86 small_complex_system.solve();
87 }
88 catch ( const std::runtime_error &error )
89 {
90 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
91 return 1;
92 }
94 answer_complex[ 0 ] = 1.0;
95 answer_complex[ 1 ] = 2.0;
96 Bc.sub( answer_complex );
97 if ( Bc.inf_norm() > tol )
98 {
99 std::cout << " Simple 2x2 (complex) system was not solved correctly\n";
100 std::cout << " residual vector's inf_norm = " << Bc.inf_norm() << "\n";
102 }
103 else
104 {
105 std::cout << " Simple 2x2 `dense' complex solver works.\n";
106 }
107
108
109
110
111
112
113 if ( failed )
114 {
115 cout << "\033[1;31;48m * FAILED \033[0m\n";
116 return 1;
117 }
118 else
119 {
120 cout << "\033[1;32;48m * PASSED \033[0m\n";
121 return 0;
122 }
123}
A linear system class for vector right-hand sides.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
double A(1.0)
initial hump amplitude