犰狳复矩阵乘法早期逼近

时间:2015-04-12 15:41:38

标签: c++ armadillo

如何提高犰狳复矩阵乘法结果的精度。它近似于小数点后4位[这是结果的一个例子(35.9682,-150.246)]但我想要至少8位小数的精度。感谢

1 个答案:

答案 0 :(得分:2)

因为你似乎不相信我在评论中所说的话:

#include <armadillo>

using namespace std;
using namespace arma;

int main(int argc, char** argv) {
  mat A = randu<mat>(4,5);
  mat B = randu<mat>(4,5);

  mat C = A*B.t();
  cout << C << endl;

  cout.precision(11);
  cout.setf(ios::fixed);
  C.raw_print(cout, "With increased precisions:");

  return 0;
}

按预期执行:

edd@max:/tmp$ g++ -o eze eze.cpp -larmadillo -lblas -llapack 
edd@max:/tmp$ ./eze  
   0.9713   1.3566   0.7946   1.6896
   1.2593   1.1457   0.9011   1.6260
   1.1954   0.8484   1.0444   1.6753
   1.6225   1.5009   1.2935   2.2019

With increased precisions:
0.97126557882 1.35660885673 0.79462856896 1.68955180769
1.25933041551 1.14565671740 0.90105251304 1.62595390611
1.19543745264 0.84844286454 1.04436441020 1.67528315350
1.62246223165 1.50087016389 1.29351914350 2.20190979625
edd@max:/tmp$ 

士气:打印精度几乎从不计算精度