After making up an algorithm with matrix, it is time to make it a working code. It is not desirable to stick to the algorithm development tool as it comes together with a big library and license. It is MTL4 's turn to play.
MTL stands for Matrix Template Library. It is C++ template based and make no dependencies on a library file nor dll. Hence it goes in a small foot print and can be deployed in any platform.
But as template library goes, the most of the work comes down to a successful compilation of the source code. There are number of things to note. First, download appropriate zip files and copies files to an appropriate folders. In Windows, you can download from here and copies whole usr folder and name it MTL4. Second there is conflict in variable names between MTL4 and WinDefs. Refer below code snippet to fix the compilation error in Windows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variable name IN below conflicts with WinDefs.h. Change it to something else like InMatrix | |
// inlcude/boost/numeric/mtl/operaiton/eigenvalue.hpp | |
eigenvalue_solver(const Matrix& IN) : ncols(num_cols(IN)), nrows(num_rows(IN)) { | |
zero= math::zero(IN[0][0]); | |
one= math::one(IN[0][0]); | |
R = hessenberg(IN); | |
// inlcude/boost/numeric/mtl/operaiton/qr_givens.hpp | |
qr_givens_solver(const Matrix& IN) : R(IN), G(2,2), Q(num_cols(IN), num_rows(IN)) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _SCL_SECURE_NO_WARNINGS | |
#define _SCL_SECURE_NO_WARNINGS // remove warning 4996 | |
#endif | |
#pragma warning( push ) | |
#pragma warning( disable: 4522 4996 4146 4355) | |
#include <boost\numeric\mtl\mtl.hpp> | |
#pragma warning( pop ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef mtl::dense2D<double> Matrix; | |
typedef mtl::dense_vector<double> Vector; | |
// matrix creation using array | |
double ct = cos(theta), st = sin(theta); | |
double m[][3]= | |
{ {ct, -st, x }, | |
{st, ct, y }, | |
{0, 0, 1 } }; | |
Matrix R_c2p( m ); | |
// inverse | |
Matrix R_p2c( inv( R_c2p ) ); | |
// fill up matrix | |
Matrix M_p(3,1); | |
M_p[0][0] = MP_p.GetX(); M_p[1][0] = MP_p.GetY(); M_p[2][0] = 1; | |
// multiplication | |
Matrix u(3,1); | |
u = R_p2c * M_p; | |
// solve | |
Matrix Ut( trans(U) ); | |
Vector UtV( Ut*V ); | |
Matrix UtU( Ut*U ); | |
Vector X( lu_solve( UtU, UtV ) ); |
No comments:
Post a Comment