// Discussion: // // Examine the math functions: // // abs // acos // acosh // asin // asinh // atan // atan2 // atanh // ceil // cos // cosh // erf // erfc // exp // floor // imag // j0 // j1 // jn // lgamma // log // log10 // max // min // pow // rint // sin // sinh // sqrt // tan // tanh // tgamma // y0 // y1 // yn // // Location: // // http://people.sc.fsu.edu/~jburkardt/freefem_src/math_test/math_test.edp // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 15 February 2015 // // Reference: // // Frederic Hecht, // Freefem++, // Third Edition, version 3.22 // cout << "\n"; cout << "math_test:\n"; cout << " FreeFem++ version\n"; cout << " Try out the FreeFem++ Math Library Functions.\n"; // // Initialize the random number generator. // int seed; // // Y = ABS ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ABS ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = abs ( x ); cout << " " << x << " " << y << "\n"; } // // Y = ACOS ( X ); // X <= 1.0 required. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ACOS ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 2.0 * randreal1 ( ) - 1.0; y = acos ( x ); cout << " " << x << " " << y << "\n"; } // // Y = ACOSH ( X ); // 1 <= |X| required. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ACOSH ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = randreal1 ( ); if ( x < 0.0 ) { x = 10.0 * x - 1.0; } else { x = 10.0 * x + 1.0; } y = acosh ( x ); cout << " " << x << " " << y << "\n"; } // // Y = ASIN ( X ); // |X| <= 1. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ASIN ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 2.0 * randreal1 ( ) - 1.0; y = asin ( x ); cout << " " << x << " " << y << "\n"; } // // Y = ASINH ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ASINH ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = asinh ( x ); cout << " " << x << " " << y << "\n"; } // // Z = ATAN ( Y / X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Z = ATAN ( Y / X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = 10.0 * randreal1 ( ) - 5.0; z = atan ( y / x ); cout << " " << x << " " << y << " " << z << "\n"; } // // Z = ATAN2 ( Y, X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Z = ATAN2 ( Y, X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = 10.0 * randreal1 ( ) - 5.0; z = atan2 ( y, x ); cout << " " << x << " " << y << " " << z << "\n"; } // // Y = ATANH ( X ); // |X| < 1 required. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ATANH ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 2.0 * randreal1 ( ) - 1.0; y = atanh ( x ); cout << " " << x << " " << y << "\n"; } // // Y = CEIL ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = CEIL ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = ceil ( x ); cout << " " << x << " " << y << "\n"; } // // Y = COS ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = COS ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = cos ( x ); cout << " " << x << " " << y << "\n"; } // // Y = COSH ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = COSH ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = cosh ( x ); cout << " " << x << " " << y << "\n"; } // // Y = ERF ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ERF ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = erf ( x ); cout << " " << x << " " << y << "\n"; } // // Y = ERFC ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = ERFC ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = erfc ( x ); cout << " " << x << " " << y << "\n"; } // // Y = EXP ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = EXP ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = exp ( x ); cout << " " << x << " " << y << "\n"; } // // Y = FLOOR ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = FLOOR ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = floor ( x ); cout << " " << x << " " << y << "\n"; } // // Y = J0 ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = J0 ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = j0 ( x ); cout << " " << x << " " << y << "\n"; } // // Y = J1 ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = J1 ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = j1 ( x ); cout << " " << x << " " << y << "\n"; } // // Y = JN ( 2, X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = JN ( 2, X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = jn ( 2, x ); cout << " " << x << " " << y << "\n"; } // // Y = LGAMMA ( X ); // X must not be 0 or a negative integer. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = LGAMMA ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ); y = lgamma ( x ); cout << " " << x << " " << y << "\n"; } // // Y = LOG ( X ); // 0 < X required. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = LOG ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ); y = log ( x ); cout << " " << x << " " << y << "\n"; } // // Y = LOG10 ( X ); // 0 < X required. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = LOG10 ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ); y = log10 ( x ); cout << " " << x << " " << y << "\n"; } // // Z = MAX ( X, Y ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Z = MAX ( X, Y ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = 10.0 * randreal1 ( ) - 5.0; z = max ( x, y ); cout << " " << x << " " << y << " " << z << "\n"; } // // Z = MIN ( X, Y ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Z = MIN ( X, Y ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = 10.0 * randreal1 ( ) - 5.0; z = min ( x, y ); cout << " " << x << " " << y << " " << z << "\n"; } // // Z = POW ( X, Y ); // If X negative, Y must be an integer. // If X 0, Y must be positive. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Z = POW ( X, Y ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ); y = 10.0 * randreal1 ( ) - 5.0; z = pow ( x, y ); cout << " " << x << " " << y << " " << z << "\n"; } // // Y = RINT ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = RINT ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = rint ( x ); cout << " " << x << " " << y << "\n"; } // // Y = SIN ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = SIN ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = sin ( x ); cout << " " << x << " " << y << "\n"; } // // Y = SINH ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = SINH ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = sinh ( x ); cout << " " << x << " " << y << "\n"; } // // Y = SQRT ( X ); // 0 <= X required. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = SQRT ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ); y = sqrt ( x ); cout << " " << x << " " << y << "\n"; } // // Y = TAN ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = TAN ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = tan ( x ); cout << " " << x << " " << y << "\n"; } // // Y = TANH ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = TANH ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = tanh ( x ); cout << " " << x << " " << y << "\n"; } // // Y = TGAMMA ( X ); // X must not be 0 or a negative integer. // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = TGAMMA ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = tgamma ( x ); cout << " " << x << " " << y << "\n"; } // // Y = Y0 ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = Y0 ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = y0 ( x ); cout << " " << x << " " << y << "\n"; } // // Y = Y1 ( X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = Y1 ( X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = y1 ( x ); cout << " " << x << " " << y << "\n"; } // // Y = YN ( 2, X ); // seed = 123456789; randinit ( seed ); cout << "\n"; cout << " Y = YN ( 2, X ):\n"; cout << "\n"; for ( int i = 0; i < 10; i++ ) { x = 10.0 * randreal1 ( ) - 5.0; y = yn ( 2, x ); cout << " " << x << " " << y << "\n"; } // // Terminate. // cout << "\n"; cout << "math_test:\n"; cout << " Normal end of execution.\n"; exit ( 0 );