Hi I'm rewriting a script from MATLAB to C++ using armadillo
library for linear algebra and matrix.
for getting more or less the same output i called cout method:
cout.precision(4);
cout.setf(ios::fixed);
but i'm getting different result:
Matlab result:
0.0000 0.0000 0.0000 0.0000 0.0000
0.0012 0.0014 0.0016 0.0020 0.0281
0.0396 0.0297 0.0297 0.0495 0.0976
Armadillo c++ result:
0.0000 0.0000 0.0000 0.0000 0.0000
0.0012 0.0014 0.0016 0.0020 0.0282
0.0416 0.0312 0.0312 0.0520 0.1027
now, i don't know if thoose little imprecision (0.039
is near to 0.041
) are caused by some errors in my C++ code translated or they should be considered normal differences between double precision in g++ and MATLAB
In my code I'm using a lot of cycle like this:
xi_summed = xi_summed + normalise((trans % (alpha.col(t) * b.t())));
where xi_summed
, trans
, alpha
, b
are arma::mat
and %
is a element-wise multiplication and mat::t()
is transpose and normalise are a function that make the entries of matrix A
array sum to 1
.