Example Vectors and Matrices with Integer EntriesThe following example shows the usage of vectors and matrices with Integer entries. In the first part, two vectors are defined and two operations for vectors are illlustrated. The second part shows matrices and some of their operations.#include <LEDA/numbers/integer_vector.h> #include <LEDA/numbers/integer_matrix.h> #include <LEDA/core/random_source.h> using namespace leda; int main() { //integer valued vectors integer_vector v1(3),v2(3); //define two 3d-zero-vectors; v1=integer_vector(1,2,3); //assign values v2=integer_vector(3,4,5); v1=v1*integer(3); //componentwise multiplication with 3 integer x=v1*v2; //scalar multiplication std::cout << "vector v1=" << v1 << std::endl; std::cout << "vector v2=" << v2 << std::endl; std::cout << "product v1*v2=" << x << std::endl; //------------------------------------------------------- //integer valued matrices integer_matrix A(3,3); //define 3x3-matrix random_source S; int i;int j; for (i=0;i<3;i++) for (j=0;j<3;j++) S >> A(i,j); //assign random values std::cout << "\nA=" << A << std::endl; //print A std::cout << "\nA^T=" << transpose(A) << std::endl; //compute and print transposed of A std::cout << "\ndeterminant of A: " << determinant(A) << std::endl; //compute and output determinant of A integer_matrix B(3,6); //define 3x6-zero-matrix and assign values for (i=0;i<3;i++) for (j=0;j<6;j++) B(i,j)=i-j-1; std::cout << "\nB=" << B << std::endl; //print B integer_matrix C=A*3; //multiplication of matrix with double std::cout << "\nC=A*3: " << C << std::endl; v2=A*v1; //multiplication of matrix with vector std::cout << "\nvector v2=A*v1: " << v2 << std::endl; C=A*B; //multiplication of two matrices std::cout << "\nC=A*B: " << C << std::endl; return 0; } |
See also:Vectors and Matrices with Double Entries Manual Entries: |