I'm having issues with floating point precision using Eigen.
I have two Eigen::MatrixXd; the first matrix A(nx1) contains only the numbers of natural numbers, and the second matrix B(nx1) contains one column filled with the same real number (ex: -0.714312).
I need to calculate the following Eigen::MatrixXd:
const auto exponential = [](double x)
{ return std::exp(x); };
MatrixXd W = B.unaryExpr(exponential);
MatrixXd residuals = A - W;
The problem is that when I print the sum of the balances:
cout << residuals.sum();
I get a different value by doing the same operation using R and the same input matrices.
Using R-matrices, I get -2.950208e-09. Although the sum of the elements A, Band Wis the same in both C++, and in R.