CppNoddy  0.92
Loading...
Searching...
No Matches
DenseVectorOpOverloading.cpp
Go to the documentation of this file.
1/// \file DenseVectorOpOverloading.cpp
2/// \ingroup Tests
3/// \ingroup Vector
4/// Just a quick and simple check that DenseVector operator
5/// overloading is functioning.
6
7#include <Types.h>
8
9using namespace CppNoddy;
10using namespace std;
11
12int main()
13{
14
15 cout << "\n";
16 cout << "=== Vector: operator overloading check ==============\n";
17 cout << "\n";
18
19 DenseVector<double> A1( 3, 1.0 );
20 DenseVector<double> B1( 3, 2.0 );
21 DenseVector<double> C1( 3, 0.0 );
22
23 const double n1 = 10. / 3.;
24
25 C1 = A1 * 10 + B1 * 5; // C1 has all elts = 20
26 C1 *= n1; // C1 has all elts = 66.66666
27
28 DenseVector<D_complex> A2( 3, 1.0 );
29 DenseVector<D_complex> B2( 3, 2.0 );
30 DenseVector<D_complex> C2( 3, 0.0 );
31
32 D_complex n2( 10.0, 10.0 );
33 D_complex m2( 5.0, 5.0 );
34 D_complex l2( 1.0, 1.0 );
35
36 C2 = A2 * n2 + B2 * m2; // C2 has all elts = (20,20)
37 C2 *= n1; // C2 has all elts = (66.6666,66.6666)
38
39 // make a complex version of C1 called C3
41 C3 = C3 * l2; // C3 has all elts = (66.6666,66.6666)
42 C2 = C2 - C3;
43
44 const double tol = 1.e-14;
45 if ( abs( C2.two_norm() ) > tol )
46 {
47 cout << "\033[1;31;48m * FAILED \033[0m\n";
48 return 1;
49 }
50 else
51 {
52 cout << "\033[1;32;48m * PASSED \033[0m\n";
53 return 0;
54 }
55}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
double two_norm() const
l2-norm.
Definition: DenseVector.cpp:54
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...
std::complex< double > D_complex
A complex double precision number using std::complex.
Definition: Types.h:98

© 2012

R.E. Hewitt