- #include <iostream>
- #include <boost/numeric/ublas/matrix.hpp>
- #include <boost/numeric/ublas/io.hpp>
- using namespace std;
- using namespace boost::numeric::ublas;
- int main()
- {
- matrix<int> A(2, 2), B(2, 2);
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- A(i, j) = i * 2 + j + 1;
- B(i, j) = i * 2 + j + 2;
- }
- }
- cout << A << endl;
- cout << B << endl;
- cout << prod(A, trans(B)) << endl;
- return 0;
- }
- /* execution result
- [2,2]((1,2),(3,4))
- [2,2]((2,3),(4,5))
- [2,2]((8,14),(18,32))
- */
上のプログラムは下記の計算を行っています.
スッキリ書けて素晴らしい.d(゚∀゚)b
0 件のコメント:
コメントを投稿