// -*- c++ -*- // // $COPYRIGHT$ // //=========================================================================== #include "mtl/matrix.h" #include "mtl/mtl.h" #include "mtl/utils.h" /* Swaps the first row with the row that has the largest element in column 1. This is the kind of operation one would do inside a Gaussian elimintation algorithm. Sample Output 3x3 [ [1,1.5,4.5], [3,2.5,9.5], [2,3.5,5.5] ] 3x3 [ [3,2.5,9.5], [1,1.5,4.5], [2,3.5,5.5] ] */ using namespace mtl; using namespace std; int main() { //begin typedef matrix< double, rectangle<>, dense, column_major>::type Matrix; const Matrix::size_type N = 3; Matrix::size_type large; double dA[] = { 1, 3, 2, 1.5, 2.5, 3.5, 4.5, 9.5, 5.5 }; Matrix A(dA, N, N); //end print_all_matrix(A); //begin // Find the largest element in the first column. large = max_index(A[0]); //end cout << "x" << endl; //begin // Swap the first row with the row containing the largest // element in the first column. swap( rows(A)[0] , rows(A)[large]); //end print_all_matrix(A); return 0; }