-- FreeFem++ v4.6 (Thu Apr 2 15:47:38 CEST 2020 - git v4.6) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // vector_test_int.edp 2 : // 3 : // Discussion: 4 : // 5 : // Demonstrate how integer vectors can be defined and manipulated. 6 : // 7 : // Location: 8 : // 9 : // http://people.sc.fsu.edu/~jburkardt/freefem_src/vector_test/vector_test_int.edp 10 : // 11 : // Modified: 12 : // 13 : // 05 July 2015 14 : // 15 : // Author: 16 : // 17 : // John Burkardt 18 : // 19 : cout << "\n"; 20 : cout << "vector_test_int:\n"; 21 : cout << " FreeFem++ version\n"; 22 : cout << " Demonstrate how integer vectors can be defined ... : and manipulated.\n"; 23 : // 24 : // Declare integer, real, and complex vectors of length 3. 25 : // 26 : int[int] iv1(3); 27 : int[int] iv2(3); 28 : int[int] iv3(3); 29 : // 30 : // Set vectors. 31 : // 32 : iv1 = 1984; 33 : iv2(0) = 1; 34 : iv2(1) = 2; 35 : iv2(2) = 3; 36 : iv3 = [ 32, 10, 21 ]; 37 : cout << "\n"; 38 : cout << " iv1 = " << iv1 << "\n"; 39 : cout << " iv2 = " << iv2 << "\n"; 40 : cout << " iv3 = " << iv3 << "\n"; 41 : // 42 : // Dimension of a vector. 43 : // 44 : cout << " iv1.n = " << iv1.n << "\n"; 45 : // 46 : // Max/Min/Sum 47 : // 48 : cout << " iv3.max = " << iv3.max << "\n"; 49 : cout << " iv3.min = " << iv3.min << "\n"; 50 : cout << " iv3.sum = " << iv3.sum << "\n"; 51 : // 52 : // Norms. 53 : // 54 : //cout << " ||iv3||_1 = " << |iv3|_1 << "\n"; 55 : //cout << " ||iv3||_2 = " << ||iv3||_2 << "\n"; 56 : //cout << " ||iv3||_infty = " << ||iv3||_infty << "\n"; 57 : // 58 : // Resize a vector. 59 : // 60 : iv3.resize ( 5 ); 61 : iv3(3) = -5; 62 : iv3(4) = 7; 63 : cout << " After iv3.resize(5), iv3.n = " << iv3.n << "\n"; 64 : cout << " iv3 = " << iv3 << "\n"; 65 : // 66 : // Sort a vector. 67 : // 68 : iv3.sort; 69 : cout << " After iv3.sort, iv3 = " << iv3 << "\n"; 70 : // 71 : // Range 72 : // 73 : iv3(2:3) = 7; 74 : cout << " After iv3(2:3)=7, iv3 = " << iv3 << "\n"; 75 : // 76 : // Use of colon to generate a sequence of values. 77 : // 78 : iv3 = 1 : 5; 79 : cout << " After iv3=1:5, iv3 = " << iv3 << "\n"; 80 : iv3 = 1 : 2 : 9; 81 : cout << " After iv3=1:2:9, iv3 = " << iv3 << "\n"; 82 : // 83 : // Arithmetic. 84 : // 85 : iv2 = 2 * iv2; 86 : cout << " iv2 = 2 * iv2 = " << iv2 << "\n"; 87 : cout << "\n"; 88 : cout << " Something wrong with the following!\n"; 89 : cout << " Presumably iv1/2 = iv1 * ( 1/2) = iv1 * 0...\n"; 90 : cout << " iv1 = " << iv1 << "\n"; 91 : // 92 : cout << "\n"; 93 : cout << " iv1 = iv1 / 2 causes runtime error!\n"; 94 : //iv1 = iv1 / 2; 95 : //cout << " iv1 = iv1 / 2 = " << iv1 << "\n"; 96 : iv1 = iv1 + 5 * iv2; 97 : cout << " iv1 = iv1 + 5 * iv2 = " << iv1 << "\n"; 98 : cout << "\n"; 99 : cout << " More bogosity.\n"; 100 : cout << " iv1 = " << iv1 << "\n"; 101 : cout << " iv2 = " << iv2 << "\n"; 102 : iv1 = iv1 ./ iv2; 103 : cout << " iv1 = iv1 ./ iv2 = " << iv2 << "\n"; 104 : cout << "\n"; 105 : cout << " More bogosity.\n"; 106 : cout << " iv1 = " << iv1 << "\n"; 107 : cout << " iv2 = " << iv2 << "\n"; 108 : iv1 = iv1 .* iv2; 109 : cout << " iv1 = iv1 .* iv2 = " << iv2 << "\n"; 110 : // 111 : // Write to file: 112 : // File will be closed once we leave this block of code. 113 : // 114 : { 115 : cout << " Write iv3 to text file.\n"; 116 : ofstream output ( "vector_test_int.txt" ); 117 : output << iv3; 118 : } 119 : // 120 : // Read from file. 121 : // 122 : cout << " Read iv4 from text file.\n"; 123 : real[int] iv4(5); 124 : ifstream input ( "vector_test_int.txt" ); 125 : input >> iv4; 126 : cout << " iv4 = " << iv4 << "\n"; 127 : // 128 : // Terminate. 129 : // 130 : cout << "\n"; 131 : cout << "vector_test_int:\n"; 132 : cout << " Normal end of execution.\n"; 133 : 134 : sizestack + 1024 =1752 ( 728 ) vector_test_int: FreeFem++ version Demonstrate how integer vectors can be defined and manipulated. iv1 = 3 1984 1984 1984 iv2 = 3 1 2 3 iv3 = 3 32 10 21 iv1.n = 3 iv3.max = 32 iv3.min = 10 iv3.sum = 63 After iv3.resize(5), iv3.n = 5 iv3 = 5 32 10 21 -5 7 After iv3.sort, iv3 = 5 -5 7 10 21 32 After iv3(2:3)=7, iv3 = 5 -5 7 7 7 32 After iv3=1:5, iv3 = 5 1 2 3 4 5 After iv3=1:2:9, iv3 = 5 1 3 5 7 9 iv2 = 2 * iv2 = 3 2 4 6 Something wrong with the following! Presumably iv1/2 = iv1 * ( 1/2) = iv1 * 0... iv1 = 3 1984 1984 1984 iv1 = iv1 / 2 causes runtime error! iv1 = iv1 + 5 * iv2 = 3 1994 2004 2014 More bogosity. iv1 = 3 1994 2004 2014 iv2 = 3 2 4 6 iv1 = iv1 ./ iv2 = 3 2 4 6 More bogosity. iv1 = 3 997 501 335 iv2 = 3 2 4 6 iv1 = iv1 .* iv2 = 3 2 4 6 Write iv3 to text file. Read iv4 from text file. iv4 = 5 1 3 5 7 9 vector_test_int: Normal end of execution. times: compile 0.00443s, execution 0.000211s, mpirank:0 CodeAlloc : nb ptr 3750, size :474152 mpirank: 0 Ok: Normal End -- FreeFem++ v4.6 (Thu Apr 2 15:47:38 CEST 2020 - git v4.6) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // vector_test_real.edp 2 : // 3 : // Discussion: 4 : // 5 : // Demonstrate how real vectors can be defined and manipulated. 6 : // 7 : // Location: 8 : // 9 : // http://people.sc.fsu.edu/~jburkardt/freefem_src/vector_test/vector_test_real.edp 10 : // 11 : // Modified: 12 : // 13 : // 05 July 2015 14 : // 15 : // Author: 16 : // 17 : // John Burkardt 18 : // 19 : cout << "\n"; 20 : cout << "vector_test_real:\n"; 21 : cout << " FreeFem++ version\n"; 22 : cout << " Demonstrate how real vectors can be defined and ... : manipulated.\n"; 23 : 24 : load "lapack" Add lapack interface ... 25 : // 26 : // Declare real vectors of length 3. 27 : // 28 : real[int] rv1(3); 29 : real[int] rv2(3); 30 : real[int] rv3(3); 31 : // 32 : // Set vectors. 33 : // 34 : rv1 = 1984.1; 35 : rv2(0) = 1.2; 36 : rv2(1) = 2.3; 37 : rv2(2) = 3.4; 38 : rv3 = [ 32.5, 10.6, 21.7 ]; 39 : cout << "\n"; 40 : cout << " rv1 = " << rv1 << "\n"; 41 : cout << " rv2 = " << rv2 << "\n"; 42 : cout << " rv3 = " << rv3 << "\n"; 43 : // 44 : // Dimension of a vector. 45 : // 46 : cout << " rv1.n = " << rv1.n << "\n"; 47 : // 48 : // Max/Min/Sum 49 : // 50 : cout << " rv3.max = " << rv3.max << "\n"; 51 : cout << " rv3.min = " << rv3.min << "\n"; 52 : cout << " rv3.sum = " << rv3.sum << "\n"; 53 : // 54 : // Norms. 55 : // 56 : cout << " rv3.l1 = " << rv3.l1 << "\n"; 57 : cout << " rv3.l2 = " << rv3.l2 << "\n"; 58 : cout << " rv3.linfty = " << rv3.linfty << "\n"; 59 : // 60 : // Resize a vector. 61 : // 62 : rv3.resize ( 5 ); 63 : rv3(3) = -5; 64 : rv3(4) = 7; 65 : cout << " After rv3.resize(5), rv3.n = " << rv3.n << "\n"; 66 : cout << " rv3 = " << rv3 << "\n"; 67 : // 68 : // Sort a vector. 69 : // 70 : rv3.sort; 71 : cout << " After rv3.sort, rv3 = " << rv3 << "\n"; 72 : // 73 : // Range 74 : // 75 : rv3(2:3) = 7; 76 : cout << " After rv3(2:3)=7, rv3 = " << rv3 << "\n"; 77 : // 78 : // Use of colon to generate a sequence of values. 79 : // 80 : rv3 = 1 : 5; 81 : cout << " After rv3=1:5, rv3 = " << rv3 << "\n"; 82 : rv3 = 1 : 2 : 9; 83 : cout << " After rv3=1:2:9, rv3 = " << rv3 << "\n"; 84 : // 85 : // Arithmetic. 86 : // 87 : rv2 = 2 * rv2; 88 : cout << " rv2 = 2 * rv2 = " << rv2 << "\n"; 89 : cout << "\n"; 90 : cout << " rv1 = " << rv1 << "\n"; 91 : // 92 : //rv1 = rv1 / 2; 93 : //cout << " rv1 = rv1 / 2 = " << rv1 << "\n"; 94 : cout << "\n"; 95 : cout << " rv1 = rv1 / 2 causes RUN TIME ERROR on some ver ... : sions.\n"; 96 : cout << "\n"; 97 : rv1 = rv1 + 5 * rv2; 98 : cout << " rv1 = rv1 + 5 * rv2 = " << rv1 << "\n"; 99 : cout << "\n"; 100 : cout << " Advertised dot div doesn't work!\n"; 101 : cout << " rv1 = " << rv1 << "\n"; 102 : cout << " rv2 = " << rv2 << "\n"; 103 : rv1 = rv1 ./ rv2; 104 : cout << " rv1 = rv1 ./ rv2 = " << rv2 << "\n"; 105 : cout << "\n"; 106 : cout << " Advertised dot star doesn't work.\n"; 107 : cout << " rv1 = " << rv1 << "\n"; 108 : cout << " rv2 = " << rv2 << "\n"; 109 : rv1 = rv1 .* rv2; 110 : cout << " rv1 = rv1 .* rv2 = " << rv2 << "\n"; 111 : // 112 : // Functions? 113 : // 114 : rv1 = [ 0.0, 1.0, 2.0, 3.0 ]; 115 : cout << " rv1 = " << rv1 << "\n"; 116 : rv2.resize ( 4 ); 117 : rv2 = sqrt ( rv1 ); 118 : cout << " rv2 = sqrt ( rv1 ) = " << rv2 << "\n"; 119 : rv2 = sin ( rv1 ); 120 : cout << " rv2 = sin ( rv1 ) = " << rv2 << "\n"; 121 : rv2 = exp ( rv1 ); 122 : cout << " rv2 = exp ( rv1 ) = " << rv2 << "\n"; 123 : // 124 : // Write to file: 125 : // 126 : { 127 : cout << " Write rv3 to text file.\n"; 128 : ofstream output ( "vector_test_real.txt" ); 129 : output << rv3; 130 : } 131 : // 132 : // Read from file. 133 : // 134 : cout << " Read rv4 from text file.\n"; 135 : real[int] rv4(5); 136 : ifstream input ( "vector_test_real.txt" ); 137 : input >> rv4; 138 : cout << " rv4 = " << rv4 << "\n"; 139 : // 140 : // Terminate. 141 : // 142 : cout << "\n"; 143 : cout << "vector_test_real:\n"; 144 : cout << " Normal end of execution.\n"; 145 : 146 : sizestack + 1024 =1752 ( 728 ) vector_test_real: FreeFem++ version Demonstrate how real vectors can be defined and manipulated. rv1 = 3 1984.1 1984.1 1984.1 rv2 = 3 1.2 2.3 3.4 rv3 = 3 32.5 10.6 21.7 rv1.n = 3 rv3.max = 32.5 rv3.min = 10.6 rv3.sum = 64.8 rv3.l1 = 64.8 rv3.l2 = 40.4907 rv3.linfty = 32.5 After rv3.resize(5), rv3.n = 5 rv3 = 5 32.5 10.6 21.7 -5 7 After rv3.sort, rv3 = 5 -5 7 10.6 21.7 32.5 After rv3(2:3)=7, rv3 = 5 -5 7 7 7 32.5 After rv3=1:5, rv3 = 5 1 2 3 4 5 After rv3=1:2:9, rv3 = 5 1 3 5 7 9 rv2 = 2 * rv2 = 3 2.4 4.6 6.8 rv1 = 3 1984.1 1984.1 1984.1 rv1 = rv1 / 2 causes RUN TIME ERROR on some versions. rv1 = rv1 + 5 * rv2 = 3 1996.1 2007.1 2018.1 Advertised dot div doesn't work! rv1 = 3 1996.1 2007.1 2018.1 rv2 = 3 2.4 4.6 6.8 rv1 = rv1 ./ rv2 = 3 2.4 4.6 6.8 Advertised dot star doesn't work. rv1 = 3 831.7083333 436.326087 296.7794118 rv2 = 3 2.4 4.6 6.8 rv1 = rv1 .* rv2 = 3 2.4 4.6 6.8 rv1 = 4 0 1 2 3 rv2 = sqrt ( rv1 ) = 4 0 1 1.414213562 1.732050808 rv2 = sin ( rv1 ) = 4 0 0.8414709848 0.9092974268 0.1411200081 rv2 = exp ( rv1 ) = 4 1 2.718281828 7.389056099 20.08553692 Write rv3 to text file. Read rv4 from text file. rv4 = 5 1 3 5 7 9 vector_test_real: Normal end of execution. times: compile 0.006497s, execution 0.000283s, mpirank:0 CodeAlloc : nb ptr 3888, size :484168 mpirank: 0 Ok: Normal End -- FreeFem++ v4.6 (Thu Apr 2 15:47:38 CEST 2020 - git v4.6) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // vector_test_complex.edp 2 : // 3 : // Discussion: 4 : // 5 : // Demonstrate how complex vectors can be defined and manipulated. 6 : // 7 : // Location: 8 : // 9 : // http://people.sc.fsu.edu/~jburkardt/freefem_src/vector_test/vector_test_complex.edp 10 : // 11 : // Modified: 12 : // 13 : // 05 July 2015 14 : // 15 : // Author: 16 : // 17 : // John Burkardt 18 : // 19 : cout << "\n"; 20 : cout << "vector_test_complex:\n"; 21 : cout << " FreeFem++ version\n"; 22 : cout << " Demonstrate how complex vectors can be defined ... : and manipulated.\n"; 23 : 24 : load "lapack" Add lapack interface ... 25 : // 26 : // Declare complex vectors of length 3. 27 : // 28 : complex[int] cv1(3); 29 : complex[int] cv2(3); 30 : complex[int] cv3(3); 31 : // 32 : // Set vectors. 33 : // 34 : cv1 = 2.1; 35 : cout << " cv1 = " << cv1 << "\n"; 36 : cv2(0) = 1 + 2i; 37 : cv2(1) = 3 - 4i; 38 : cv2(2) = 5 + 6i; 39 : cout << " cv2 = " << cv2 << "\n"; 40 : cv3 = [ 1i, 2-3i, 0.5 ]; 41 : cout << " cv3 = " << cv3 << "\n"; 42 : // 43 : // Dimension of a vector. 44 : // 45 : cout << " cv1.n = " << cv1.n << "\n"; 46 : // 47 : // Max/Min/Sum 48 : // Note that complex max and min are real and imaginary component-wise. 49 : // 50 : cout << " cv3.max = " << cv3.max << "\n"; 51 : cout << " cv3.min = " << cv3.min << "\n"; 52 : cout << " cv3.sum = " << cv3.sum << "\n"; 53 : // 54 : // Norms. 55 : // 56 : cout << " cv3.l1 = " << cv3.l1 << "\n"; 57 : cout << " cv3.l2 = " << cv3.l2 << "\n"; 58 : cout << " cv3.linfty = " << cv3.linfty << "\n"; 59 : // 60 : // Resize a vector. 61 : // 62 : cv3.resize ( 5 ); 63 : cv3(3) = -5+4.5i; 64 : cv3(4) = 7+2i; 65 : cout << " After cv3.resize(5), cv3.n = " << cv3.n << "\n"; 66 : cout << " cv3 = " << cv3 << "\n"; 67 : // 68 : // Sort a vector. 69 : // Cannot sort a complex vector... 70 : // 71 : //cv3.sort; 72 : //cout << " After cv3.sort, cv3 = " << cv3 << "\n"; 73 : // 74 : // Range 75 : // 76 : cv3(2:3) = 7; 77 : cout << " After cv3(2:3)=7, cv3 = " << cv3 << "\n"; 78 : // 79 : // Arithmetic. 80 : // 81 : cv2 = 0.5 * cv2; 82 : cout << " cv2 = 0.5 * cv2 = " << cv2 << "\n"; 83 : cv2 = 1i * cv2; 84 : cout << " cv2 = 1i * cv2 = " << cv2 << "\n"; 85 : cout << "\n"; 86 : cout << " cv1 = " << cv1 << "\n"; 87 : cout << "\n"; 88 : cv1 = cv1 + 1.5 * cv2; 89 : cout << " cv1 = cv1 + 1.5 * cv2 = " << cv1 << "\n"; 90 : // 91 : // Functions? 92 : // 93 : cout << " cv1 = " << cv1 << "\n"; 94 : cv2 = sqrt ( cv1 ); 95 : cout << " cv2 = sqrt ( cv1 ) = " << cv2 << "\n"; 96 : cv2 = sin ( cv1 ); 97 : cout << " cv2 = sin ( cv1 ) = " << cv2 << "\n"; 98 : cv2 = exp ( cv1 ); 99 : cout << " cv2 = exp ( cv1 ) = " << cv2 << "\n"; 100 : // 101 : // Write to file: 102 : // 103 : { 104 : cout << " Write cv3 to text file.\n"; 105 : ofstream output ( "vector_test_complex.txt" ); 106 : output << cv3; 107 : } 108 : // 109 : // Read from file. 110 : // 111 : cout << " Read cv4 from text file.\n"; 112 : complex[int] cv4(5); 113 : ifstream input ( "vector_test_complex.txt" ); 114 : input >> cv4; 115 : cout << " cv4 = " << cv4 << "\n"; 116 : // 117 : // Terminate. 118 : // 119 : cout << "\n"; 120 : cout << "vector_test_complex:\n"; 121 : cout << " Normal end of execution.\n"; 122 : 123 : sizestack + 1024 =1752 ( 728 ) vector_test_complex: FreeFem++ version Demonstrate how complex vectors can be defined and manipulated. cv1 = 3 (2.1,0) (2.1,0) (2.1,0) cv2 = 3 (1,2) (3,-4) (5,6) cv3 = 3 (0,1) (2,-3) (0.5,0) cv1.n = 3 cv3.max = (2,1) cv3.min = (0,-3) cv3.sum = (2.5,-2) cv3.l1 = 5.10555 cv3.l2 = 3.77492 cv3.linfty = 3.60555 After cv3.resize(5), cv3.n = 5 cv3 = 5 (0,1) (2,-3) (0.5,0) (-5,4.5) (7,2) After cv3(2:3)=7, cv3 = 5 (0,1) (2,-3) (7,0) (7,0) (7,2) cv2 = 0.5 * cv2 = 3 (0.5,1) (1.5,-2) (2.5,3) cv2 = 1i * cv2 = 3 (-1,0.5) (2,1.5) (-3,2.5) cv1 = 3 (2.1,0) (2.1,0) (2.1,0) cv1 = cv1 + 1.5 * cv2 = 3 (0.6,0.75) (5.1,2.25) (-2.4,3.75) cv1 = 3 (0.6,0.75) (5.1,2.25) (-2.4,3.75) cv2 = sqrt ( cv1 ) = 3 (0.883308733,0.4245401251) (2.310224151,0.4869657343) (1.012977449,1.850979014) cv2 = sin ( cv1 ) = 3 (0.7310331721,0.6786872856) (-4.440732644,1.773157207) (-14.36865533,-15.6687184) cv2 = exp ( cv1 ) = 3 (1.333224044,1.2420268) (-103.0342357,127.6210498) (-0.07443946545,-0.05185087302) Write cv3 to text file. Read cv4 from text file. cv4 = 5 (0,1) (2,-3) (7,0) (7,0) (7,2) vector_test_complex: Normal end of execution. times: compile 0.005401s, execution 0.000295s, mpirank:0 CodeAlloc : nb ptr 3789, size :482016 mpirank: 0 Ok: Normal End