03 February 2012 08:49:56 PM TEST_MIN_PRB C++ version Test the TEST_MIN library. TEST01 For each problem, print the title. Problem Title 1 Simple quadratic, (x-2)^2+1. 2 Quadratic plus exponential, x^2 + e^(-x). 3 Quartic, x^4 + 2x^2 + x + 3. 4 Steep valley, e^x + 1/(100x). 5 Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2). 6 line, 2 - x. 7 The dying snake, ( x + sin(x) ) * e^(-x^2). 8 The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4 9 The oscillatory parabola 10 The cosine combo 11 1 + |3x-1| TEST02 For each problem, evaluate the function at the starting point and the solution. Problem 1 Simple quadratic, (x-2)^2+1. F(X_START) = 2.30323 F(X_SOL) = 1 Problem 2 Quadratic plus exponential, x^2 + e^(-x). F(X_START) = 1.08933 F(X_SOL) = 0.827184 Problem 3 Quartic, x^4 + 2x^2 + x + 3. F(X_START) = 14.0625 F(X_SOL) = 2.87849 Problem 4 Steep valley, e^x + 1/(100x). F(X_START) = 2.59624 F(X_SOL) = 1.20492 Problem 5 Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2). F(X_START) = 1.48836 F(X_SOL) = 0.628026 Problem 6 line, 2 - x. F(X_START) = -5.2 F(X_SOL) = -7 Problem 7 The dying snake, ( x + sin(x) ) * e^(-x^2). F(X_START) = -5.61222e-11 F(X_SOL) = -0.824239 Problem 8 The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4 F(X_START) = 29.7647 F(X_SOL) = -10000 Problem 9 The oscillatory parabola F(X_START) = 9.36573 F(X_SOL) = -9.97791 Problem 10 The cosine combo F(X_START) = -1.33593 F(X_SOL) = -13.0797 Problem 11 1 + |3x-1| F(X_START) = 2.25 F(X_SOL) = 1 TEST03 For each problem, compare the exact and approximate gradients at the starting point. Problem 1 Simple quadratic, (x-2)^2+1. X 3.14159 F'(X) (exact) 2.28319 F'(X) (difference) 2.28319 Problem 2 Quadratic plus exponential, x^2 + e^(-x). X 0.8 F'(X) (exact) 1.15067 F'(X) (difference) 1.15067 Problem 3 Quartic, x^4 + 2x^2 + x + 3. X 1.5 F'(X) (exact) 20.5 F'(X) (difference) 20.5 Problem 4 Steep valley, e^x + 1/(100x). X 0.95 F'(X) (exact) 2.57463 F'(X) (difference) 2.57463 Problem 5 Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2). X 1.5 F'(X) (exact) 2.47725 F'(X) (difference) 2.47725 Problem 6 line, 2 - x. X 7.2 F'(X) (exact) -1 F'(X) (difference) -1 Problem 7 The dying snake, ( x + sin(x) ) * e^(-x^2). X -5 F'(X) (exact) -5.43395e-10 F'(X) (difference) -5.43395e-10 Problem 8 The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4 X 3.1 F'(X) (exact) 18.1064 F'(X) (difference) 18.1064 Problem 9 The oscillatory parabola X -2 F'(X) (exact) 55.0698 F'(X) (difference) 55.0698 Problem 10 The cosine combo X 0.5 F'(X) (exact) 41.2254 F'(X) (difference) 41.2254 Problem 11 1 + |3x-1| X 0.75 F'(X) (exact) 3 F'(X) (difference) 3 TEST04 For each problem, compare the exact and approximate second derivatives at the starting point. Problem 1 Simple quadratic, (x-2)^2+1. X: 3.14159 F"(X) (exact): 2 F"(X) (difference): 2 Problem 2 Quadratic plus exponential, x^2 + e^(-x). X: 0.8 F"(X) (exact): 2.44933 F"(X) (difference): 2.44933 Problem 3 Quartic, x^4 + 2x^2 + x + 3. X: 1.5 F"(X) (exact): 31 F"(X) (difference): 31 Problem 4 Steep valley, e^x + 1/(100x). X: 0.95 F"(X) (exact): 2.60904 F"(X) (difference): 2.60904 Problem 5 Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2). X: 1.5 F"(X) (exact): 4.48761 F"(X) (difference): 4.48762 Problem 6 line, 2 - x. X: 7.2 F"(X) (exact): 0 F"(X) (difference): 0 Problem 7 The dying snake, ( x + sin(x) ) * e^(-x^2). X: -5 F"(X) (exact): 8.39789e-09 F"(X) (difference): -5.15675e-09 Problem 8 The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4 X: 3.1 F"(X) (exact): -5.86854 F"(X) (difference): -5.86855 Problem 9 The oscillatory parabola X: -2 F"(X) (exact): -277.798 F"(X) (difference): -277.798 Problem 10 The cosine combo X: 0.5 F"(X) (exact): 177.651 F"(X) (difference): 177.651 Problem 11 1 + |3x-1| X: 0.75 F"(X) (exact): 0 F"(X) (difference): 0 TEST05 For each problem, take a few steps of the bisection method. Problem 1 Simple quadratic, (x-2)^2+1. 0 X: 0 1.5708 3.14159 F: 5 1.18422 2.30323 1 X: 1.5708 2.35619 3.14159 F: 1.18422 1.12687 2.30323 2 X: 1.5708 1.9635 2.35619 F: 1.18422 1.00133 1.12687 3 X: 1.76715 1.9635 2.15984 F: 1.05422 1.00133 1.02555 4 X: 1.86532 1.9635 2.06167 F: 1.01814 1.00133 1.0038 5 X: 1.9635 2.01258 2.06167 F: 1.00133 1.00016 1.0038 6 X: 1.9635 1.98804 2.01258 F: 1.00133 1.00014 1.00016 7 X: 1.98804 2.00031 2.01258 F: 1.00014 1 1.00016 8 X: 1.99418 2.00031 2.00645 F: 1.00003 1 1.00004 9 X: 1.99724 2.00031 2.00338 F: 1.00001 1 1.00001 10 X: 1.99878 2.00031 2.00184 F: 1 1 1 Problem 2 Quadratic plus exponential, x^2 + e^(-x). 0 X: 0 0.5 1 F: 1 0.856531 1.36788 1 X: 0 0.25 0.5 F: 1 0.841301 0.856531 2 X: 0.25 0.375 0.5 F: 0.841301 0.827914 0.856531 3 X: 0.3125 0.375 0.4375 F: 0.829272 0.827914 0.837055 4 X: 0.3125 0.34375 0.375 F: 0.829272 0.82727 0.827914 5 X: 0.34375 0.359375 0.375 F: 0.82727 0.827263 0.827914 6 X: 0.34375 0.351562 0.359375 F: 0.82727 0.827184 0.827263 7 X: 0.347656 0.351562 0.355469 F: 0.827207 0.827184 0.827203 8 X: 0.349609 0.351562 0.353516 F: 0.82719 0.827184 0.827188 9 X: 0.350586 0.351562 0.352539 F: 0.827186 0.827184 0.827185 10 X: 0.351074 0.351562 0.352051 F: 0.827185 0.827184 0.827184 Problem 3 Quartic, x^4 + 2x^2 + x + 3. 0 X: -2 0 2 F: 25 3 29 1 X: -1 0 1 F: 5 3 7 2 X: -0.5 0 0.5 F: 3.0625 3 4.0625 3 X: -0.5 -0.25 0 F: 3.0625 2.87891 3 4 X: -0.375 -0.25 -0.125 F: 2.92603 2.87891 2.90649 5 X: -0.3125 -0.25 -0.1875 F: 2.89235 2.87891 2.88405 6 X: -0.28125 -0.25 -0.21875 F: 2.88321 2.87891 2.87924 7 X: -0.25 -0.234375 -0.21875 F: 2.87891 2.87851 2.87924 8 X: -0.242188 -0.234375 -0.226562 F: 2.87856 2.87851 2.87873 9 X: -0.242188 -0.238281 -0.234375 F: 2.87856 2.8785 2.87851 10 X: -0.238281 -0.236328 -0.234375 F: 2.8785 2.87849 2.87851 Problem 4 Steep valley, e^x + 1/(100x). 0 X: 0.0001 0.50005 1 F: 101 1.6688 2.72828 1 X: 0.0001 0.250075 0.50005 F: 101 1.32411 1.6688 2 X: 0.0001 0.125087 0.250075 F: 101 1.21319 1.32411 3 X: 0.0625937 0.125087 0.187581 F: 1.22435 1.21319 1.25964 4 X: 0.0625937 0.0938406 0.125087 F: 1.22435 1.20495 1.21319 5 X: 0.0782172 0.0938406 0.109464 F: 1.20921 1.20495 1.20703 6 X: 0.0860289 0.0938406 0.101652 F: 1.20608 1.20495 1.20537 7 X: 0.0899348 0.0938406 0.0977465 F: 1.20529 1.20495 1.20499 8 X: 0.0938406 0.0957936 0.0977465 F: 1.20495 1.20492 1.20499 9 X: 0.0948171 0.0957936 0.09677 F: 1.20492 1.20492 1.20494 10 X: 0.0948171 0.0953053 0.0957936 F: 1.20492 1.20492 1.20492 Problem 5 Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2). 0 X: 0.0002 1.0001 2 F: 25.9998 0.728352 3.39406 1 X: 0.0002 0.50015 1.0001 F: 25.9998 0.668659 0.728352 2 X: 0.50015 0.750125 1.0001 F: 0.668659 0.630344 0.728352 3 X: 0.625137 0.750125 0.875112 F: 0.634222 0.630344 0.660346 4 X: 0.625137 0.687631 0.750125 F: 0.634222 0.628277 0.630344 5 X: 0.656384 0.687631 0.718878 F: 0.630273 0.628277 0.628282 6 X: 0.687631 0.703255 0.718878 F: 0.628277 0.628026 0.628282 7 X: 0.695443 0.703255 0.711066 F: 0.628088 0.628026 0.62809 8 X: 0.699349 0.703255 0.707161 F: 0.628041 0.628026 0.628042 9 X: 0.701302 0.703255 0.705208 F: 0.628029 0.628026 0.62803 10 X: 0.702278 0.703255 0.704231 F: 0.628027 0.628026 0.628027 Problem 6 line, 2 - x. 0 X: 7 8 9 F: -5 -6 -7 1 X: 8 8.5 9 F: -6 -6.5 -7 2 X: 8.5 8.75 9 F: -6.5 -6.75 -7 3 X: 8.75 8.875 9 F: -6.75 -6.875 -7 4 X: 8.875 8.9375 9 F: -6.875 -6.9375 -7 5 X: 8.9375 8.96875 9 F: -6.9375 -6.96875 -7 6 X: 8.96875 8.98438 9 F: -6.96875 -6.98438 -7 7 X: 8.98438 8.99219 9 F: -6.98438 -6.99219 -7 8 X: 8.99219 8.99609 9 F: -6.99219 -6.99609 -7 9 X: 8.99609 8.99805 9 F: -6.99609 -6.99805 -7 10 X: 8.99805 8.99902 9 F: -6.99805 -6.99902 -7 Problem 7 The dying snake, ( x + sin(x) ) * e^(-x^2). 0 X: -10 0 10 F: -3.5177e-43 0 3.5177e-43 1 X: -10 -5 0 F: -3.5177e-43 -5.61222e-11 0 2 X: -5 -2.5 0 F: -5.61222e-11 -0.00598146 0 3 X: -2.5 -1.25 0 F: -0.00598146 -0.460932 0 4 X: -1.25 -0.625 0 F: -0.460932 -0.818793 0 5 X: -0.9375 -0.625 -0.3125 F: -0.723999 -0.818793 -0.56226 6 X: -0.78125 -0.625 -0.46875 F: -0.806819 -0.818793 -0.738938 7 X: -0.78125 -0.703125 -0.625 F: -0.806819 -0.823262 -0.818793 8 X: -0.703125 -0.664062 -0.625 F: -0.823262 -0.823807 -0.818793 9 X: -0.703125 -0.683594 -0.664062 F: -0.823262 -0.824211 -0.823807 10 X: -0.693359 -0.683594 -0.673828 F: -0.823903 -0.824211 -0.82418 Problem 8 The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4 0 X: 2 3 4 F: 13.0027 27.9599 48.9969 1 X: 2 2.5 3 F: 13.0027 19.7409 27.9599 2 X: 2 2.25 2.5 F: 13.0027 16.1851 19.7409 3 X: 2 2.125 2.25 F: 13.0027 14.5472 16.1851 4 X: 2 2.0625 2.125 F: 13.0027 13.7633 14.5472 5 X: 2 2.03125 2.0625 F: 13.0027 13.3801 13.7633 6 X: 2 2.01562 2.03125 F: 13.0027 13.1907 13.3801 7 X: 2 2.00781 2.01562 F: 13.0027 13.0965 13.1907 8 X: 2 2.00391 2.00781 F: 13.0027 13.0496 13.0965 9 X: 2 2.00195 2.00391 F: 13.0027 13.0261 13.0496 10 X: 2 2.00098 2.00195 F: 13.0027 13.0144 13.0261 Problem 9 The oscillatory parabola 0 X: -5 0 5 F: 34.1652 -9.09297 30.3657 1 X: -2.5 0 2.5 F: 6.67024 -9.09297 -0.566388 2 X: -1.25 0 1.25 F: -7.00696 -9.09297 3.42653 3 X: -0.625 0 0.625 F: 9.40912 -9.09297 -4.54016 4 X: -0.3125 0 0.3125 F: -0.964699 -9.09297 -9.071 5 X: 0 0.15625 0.3125 F: -9.09297 -9.97444 -9.071 6 X: 0.078125 0.15625 0.234375 F: -9.79271 -9.97444 -9.70624 7 X: 0.117188 0.15625 0.195312 F: -9.94455 -9.97444 -9.89162 8 X: 0.136719 0.15625 0.175781 F: -9.97419 -9.97444 -9.9465 9 X: 0.136719 0.146484 0.15625 F: -9.97419 -9.97791 -9.97444 10 X: 0.141602 0.146484 0.151367 F: -9.97696 -9.97791 -9.97707 Problem 10 The cosine combo 0 X: 0 3.5 7 F: 16 3.41326 13.3791 1 X: 0 1.75 3.5 F: 16 -10.1153 3.41326 2 X: 0.875 1.75 2.625 F: -1.79798 -10.1153 -0.258664 3 X: 1.3125 1.75 2.1875 F: 9.22252 -10.1153 -4.48318 4 X: 1.53125 1.75 1.96875 F: 4.72684 -10.1153 -5.22843 5 X: 1.64062 1.75 1.85938 F: -4.28243 -10.1153 -9.61944 6 X: 1.75 1.80469 1.85938 F: -10.1153 -10.6305 -9.61944 7 X: 1.77734 1.80469 1.83203 F: -10.5825 -10.6305 -10.2914 8 X: 1.77734 1.79102 1.80469 F: -10.5825 -10.6574 -10.6305 9 X: 1.78418 1.79102 1.79785 F: -10.6329 -10.6574 -10.6564 10 X: 1.79102 1.79443 1.79785 F: -10.6574 -10.6601 -10.6564 Problem 11 1 + |3x-1| 0 X: 0 0.5 1 F: 2 1.5 3 1 X: 0 0.25 0.5 F: 2 1.25 1.5 2 X: 0.25 0.375 0.5 F: 1.25 1.125 1.5 3 X: 0.25 0.3125 0.375 F: 1.25 1.0625 1.125 4 X: 0.3125 0.34375 0.375 F: 1.0625 1.03125 1.125 5 X: 0.3125 0.328125 0.34375 F: 1.0625 1.01562 1.03125 6 X: 0.328125 0.335938 0.34375 F: 1.01562 1.00781 1.03125 7 X: 0.328125 0.332031 0.335938 F: 1.01562 1.00391 1.00781 8 X: 0.332031 0.333984 0.335938 F: 1.00391 1.00195 1.00781 9 X: 0.332031 0.333008 0.333984 F: 1.00391 1.00098 1.00195 10 X: 0.333008 0.333496 0.333984 F: 1.00098 1.00049 1.00195 TEST06 For each problem, use Brent's method. Problem 1 Simple quadratic, (x-2)^2+1. Initial interval [A,B]: A, B: 0 3.14159 FA, FB: 5 2.30323 Final interval [A,X*,B]: A, X*, B: 2 2 2 FA, FX*, FB: 1 1 1 Problem 2 Quadratic plus exponential, x^2 + e^(-x). Initial interval [A,B]: A, B: 0 1 FA, FB: 1 1.36788 Final interval [A,X*,B]: A, X*, B: 0.351733 0.351734 0.351734 FA, FX*, FB: 0.827184 0.827184 0.827184 Problem 3 Quartic, x^4 + 2x^2 + x + 3. Initial interval [A,B]: A, B: -2 2 FA, FB: 25 29 Final interval [A,X*,B]: A, X*, B: -0.236733 -0.236733 -0.236733 FA, FX*, FB: 2.87849 2.87849 2.87849 Problem 4 Steep valley, e^x + 1/(100x). Initial interval [A,B]: A, B: 0.0001 1 FA, FB: 101 2.72828 Final interval [A,X*,B]: A, X*, B: 0.0953443 0.0953446 0.095345 FA, FX*, FB: 1.20492 1.20492 1.20492 Problem 5 Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2). Initial interval [A,B]: A, B: 0.0002 2 FA, FB: 25.9998 3.39406 Final interval [A,X*,B]: A, X*, B: 0.703205 0.703205 0.703205 FA, FX*, FB: 0.628026 0.628026 0.628026 Problem 6 line, 2 - x. Initial interval [A,B]: A, B: 7 9 FA, FB: -5 -7 Final interval [A,X*,B]: A, X*, B: 9 9 9 FA, FX*, FB: -7 -7 -7 Problem 7 The dying snake, ( x + sin(x) ) * e^(-x^2). Initial interval [A,B]: A, B: -10 10 FA, FB: -3.5177e-43 3.5177e-43 Final interval [A,X*,B]: A, X*, B: -0.679579 -0.679579 -0.679578 FA, FX*, FB: -0.824239 -0.824239 -0.824239 Problem 8 The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4 Initial interval [A,B]: A, B: 2 4 FA, FB: 13.0027 48.9969 Final interval [A,X*,B]: A, X*, B: 2 2 2 FA, FX*, FB: 13.0027 13.0027 13.0027 Problem 9 The oscillatory parabola Initial interval [A,B]: A, B: -5 5 FA, FB: 34.1652 30.3657 Final interval [A,X*,B]: A, X*, B: -1.33845 -1.33845 -1.33845 FA, FX*, FB: -8.19742 -8.19742 -8.19742 Problem 10 The cosine combo Initial interval [A,B]: A, B: 0 7 FA, FB: 16 13.3791 Final interval [A,X*,B]: A, X*, B: 1.01678 1.01678 1.01678 FA, FX*, FB: -6.28275 -6.28275 -6.28275 Problem 11 1 + |3x-1| Initial interval [A,B]: A, B: 0 1 FA, FB: 2 3 Final interval [A,X*,B]: A, X*, B: 0.333333 0.333334 0.333334 FA, FX*, FB: 1 1 1 TEST_MIN_PRB Normal end of execution. 03 February 2012 08:49:56 PM