// vector_test_int.edp // // Discussion: // // Demonstrate how integer vectors can be defined and manipulated. // // Location: // // http://people.sc.fsu.edu/~jburkardt/freefem_src/vector_test/vector_test_int.edp // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 05 July 2015 // // Author: // // John Burkardt // cout << "\n"; cout << "vector_test_int:\n"; cout << " FreeFem++ version\n"; cout << " Demonstrate how integer vectors can be defined and manipulated.\n"; // // Declare integer, real, and complex vectors of length 3. // int[int] iv1(3); int[int] iv2(3); int[int] iv3(3); // // Set vectors. // iv1 = 1984; iv2(0) = 1; iv2(1) = 2; iv2(2) = 3; iv3 = [ 32, 10, 21 ]; cout << "\n"; cout << " iv1 = " << iv1 << "\n"; cout << " iv2 = " << iv2 << "\n"; cout << " iv3 = " << iv3 << "\n"; // // Dimension of a vector. // cout << " iv1.n = " << iv1.n << "\n"; // // Max/Min/Sum // cout << " iv3.max = " << iv3.max << "\n"; cout << " iv3.min = " << iv3.min << "\n"; cout << " iv3.sum = " << iv3.sum << "\n"; // // Norms. // //cout << " ||iv3||_1 = " << |iv3|_1 << "\n"; //cout << " ||iv3||_2 = " << ||iv3||_2 << "\n"; //cout << " ||iv3||_infty = " << ||iv3||_infty << "\n"; // // Resize a vector. // iv3.resize ( 5 ); iv3(3) = -5; iv3(4) = 7; cout << " After iv3.resize(5), iv3.n = " << iv3.n << "\n"; cout << " iv3 = " << iv3 << "\n"; // // Sort a vector. // iv3.sort; cout << " After iv3.sort, iv3 = " << iv3 << "\n"; // // Range // iv3(2:3) = 7; cout << " After iv3(2:3)=7, iv3 = " << iv3 << "\n"; // // Use of colon to generate a sequence of values. // iv3 = 1 : 5; cout << " After iv3=1:5, iv3 = " << iv3 << "\n"; iv3 = 1 : 2 : 9; cout << " After iv3=1:2:9, iv3 = " << iv3 << "\n"; // // Arithmetic. // iv2 = 2 * iv2; cout << " iv2 = 2 * iv2 = " << iv2 << "\n"; cout << "\n"; cout << " Something wrong with the following!\n"; cout << " Presumably iv1/2 = iv1 * ( 1/2) = iv1 * 0...\n"; cout << " iv1 = " << iv1 << "\n"; // cout << "\n"; cout << " iv1 = iv1 / 2 causes runtime error!\n"; //iv1 = iv1 / 2; //cout << " iv1 = iv1 / 2 = " << iv1 << "\n"; iv1 = iv1 + 5 * iv2; cout << " iv1 = iv1 + 5 * iv2 = " << iv1 << "\n"; cout << "\n"; cout << " More bogosity.\n"; cout << " iv1 = " << iv1 << "\n"; cout << " iv2 = " << iv2 << "\n"; iv1 = iv1 ./ iv2; cout << " iv1 = iv1 ./ iv2 = " << iv2 << "\n"; cout << "\n"; cout << " More bogosity.\n"; cout << " iv1 = " << iv1 << "\n"; cout << " iv2 = " << iv2 << "\n"; iv1 = iv1 .* iv2; cout << " iv1 = iv1 .* iv2 = " << iv2 << "\n"; // // Write to file: // File will be closed once we leave this block of code. // { cout << " Write iv3 to text file.\n"; ofstream output ( "vector_test_int.txt" ); output << iv3; } // // Read from file. // cout << " Read iv4 from text file.\n"; real[int] iv4(5); ifstream input ( "vector_test_int.txt" ); input >> iv4; cout << " iv4 = " << iv4 << "\n"; // // Terminate. // cout << "\n"; cout << "vector_test_int:\n"; cout << " Normal end of execution.\n"; exit ( 0 );