| 72 | |
| 73 | template <typename T> |
| 74 | void testPascal(double tol) |
| 75 | { |
| 76 | for (int size=1; size<20; size++) |
| 77 | { |
| 78 | Matrix<T,Dynamic,Dynamic> A(size,size), B(size,size), C(size,size); |
| 79 | A.setZero(); |
| 80 | for (int i=0; i<size-1; i++) |
| 81 | A(i+1,i) = static_cast<T>(i+1); |
| 82 | B.setZero(); |
| 83 | for (int i=0; i<size; i++) |
| 84 | for (int j=0; j<=i; j++) |
| 85 | B(i,j) = static_cast<T>(binom(i,j)); |
| 86 | |
| 87 | C = A.matrixFunction(expfn); |
| 88 | std::cout << "testPascal: size = " << size << " error funm = " << relerr(C, B); |
| 89 | VERIFY(C.isApprox(B, static_cast<T>(tol))); |
| 90 | |
| 91 | C = A.exp(); |
| 92 | std::cout << " error expm = " << relerr(C, B) << "\n"; |
| 93 | VERIFY(C.isApprox(B, static_cast<T>(tol))); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | template<typename MatrixType> |
| 98 | void randomTest(const MatrixType& m, double tol) |