|
Boost Users : |
From: Minkoo Seo (minkoo.seo_at_[hidden])
Date: 2006-08-18 03:19:34
Hi list.
I got a problem of matrix initialization. Please
see the following code:
#include <iostream>
#include <iterator>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace std;
using namespace boost::numeric::ublas;
int main ()
{
matrix<double> m(3, 3);
for (unsigned i = 0; i < 3; i++)
m(i, i) = -i;
cout << m << endl;
return EXIT_SUCCESS;
}
In this code, I'm trying to initialize the diagonal with
-1, -2, -3. But, the result is obviously different from
what I expected:
[3,3]((0,0,0),(0,4.29497e+09,0),(0,0,4.29497e+09))
This must be due to type conversion from unsigned from double
that occurs at 'm(i, i) = -i'. IMHO, the code must works as follows
i // unsigned
-i // (-1) * i = int * unsigned = int
m(i, i) = -i // lhs is double, so int on rhs should be converted
// into double.
But the result implies that I'm wrong. Anybody knows what I'm
missing here?
How would you correct the above code?
Sincerely,
Minkoo Seo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net