Ticket #3539: test_ublas.cpp

File test_ublas.cpp, 1.3 KB (added by karvind.umich@…, 13 years ago)

test code that produces error

Line 
1#include <boost/numeric/ublas/vector.hpp>
2#include <boost/numeric/ublas/io.hpp>
3#include <boost/numeric/ublas/matrix.hpp>
4#include <complex>
5
6using namespace boost::numeric::ublas;
7//using namespace std;
8
9int main(void) {
10
11 typedef std::complex<double> dComplex;
12 vector<dComplex> v(4);
13 //std::cout << v.size() << std::endl;
14 //v.resize(4);
15
16 for (int i=0;i<v.size();++i)
17 v[i] = dComplex( i, i+1 );
18
19 std::cout << v << std::endl;
20
21 std::cout << "L1 norm = " << norm_1(v) << std::endl;
22 std::cout << "L2 norm = " << norm_2(v) << std::endl;
23 std::cout << "index of Linf norm " << index_norm_inf(v) << std::endl;
24 std::cout << "Linf norm = " << norm_inf(v) << " - this is wrong, should |3+4j| = 5" << std::endl;
25 std::cout << "Linf norm = " << abs(v[3]) << " - this is the correct answer" << std::endl;
26
27 v *= 3.;
28
29 std::cout << std::endl << v << std::endl;
30
31 std::cout << "L1 norm = " << norm_1(v) << std::endl;
32 std::cout << "L2 norm = " << norm_2(v) << std::endl;
33 std::cout << "index of Linf norm " << index_norm_inf(v) << std::endl;
34 std::cout << "Linf norm = " << norm_inf(v) << " - this is wrong, should |9+12j| = 15" << std::endl;
35 std::cout << "Linf norm = " << abs(v[3]) << " - this is the correct answer" << std::endl;
36 return 0;
37}
38
39