// -*- c++ -*- // // $COPYRIGHT$ // //=========================================================================== #include "mtl/matrix.h" #include "mtl/mtl.h" #include "mtl/utils.h" #include "mtl/linalg_vec.h" #include /* This example uses matrix-vector multiplication to rotates a vector. Sample Output Original vector: [3,4,] Rotated vector: [-2,1.5,] */ using namespace mtl; using namespace std; int main() { //begin // Use the matrix generator to select a matrix type typedef matrix< double, rectangle<>, dense<>, column_major>::type Matrix; // Use the std::vector based dense1D for our Vector type typedef dense1D Vector; const int N = 2; double pi, theta; // Create the matrix object, with dimensions NxN Matrix rot(N, N); // Create two vectors of length N Vector vec1(N),vec2(N); pi = 4.0 * atan (1.0); theta = pi / 2.0; // Assign some values into Matrix rot rot(0,0) = cos(theta); rot(1,0) = sin(theta); rot(0,1) = -sin(theta); rot(1,1) = cos(theta); // Assign some values into vec1 vec1[0] = 3.0; vec1[1] = 4.0; //end cout << endl; cout << "Original vector: "; print_vector(vec1); cout << endl; //begin // Compute rot*vec1*0.5 -> vec2 // This uses the 3 argument version of mtl::mult. // mtl::mult(A,x,y), A*x -> y // where in this example A=rot,x=(vec1*0.5), y=vec2 mult(rot, scaled(vec1, 0.5), vec2); //end cout << "Rotated vector: "; print_vector(vec2); return 0; }