24 January 2017 03:26:31 PM TEST_INTERP_FUN_PRB C version Test the TEST_INTERP_FUN library. TEST01 Demonstrate some of the bookkeeping routines. P00_PROB_NUM returns the number of problems. P00_TITLE returns the problem title. P00_LIMIT returns the problem limits. Number of problems = 5 Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". Problem lower limit A = -5 Problem upper limit B = 5 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". Problem lower limit A = -1 Problem upper limit B = 1 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". Problem lower limit A = -1 Problem upper limit B = 1 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". Problem lower limit A = 0 Problem upper limit B = 1 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". Problem lower limit A = 0 Problem upper limit B = 10 TEST02 P00_STORY prints the problem "story". Problem 1 This is a famous example, due to Runge. If equally spaced abscissas are used, the sequence of interpolating polynomials Pn(X) diverges, in the sense that the max norm of the difference between Pn(X) and F(X) becomes arbitrarily large as N increases. Problem 2 This example is due to Bernstein. If equally spaced abscissas are used, the sequence of interpolating polynomials Pn(X) only converges to F(X) at -1, 0, and 1. Problem 3 The step function is discontinuous. Attempts to approximate this function by high degree polynomials will rapidly diverge. Problem 4 The Doppler function is continuous, but highly oscillatory near the value X = 0. Problem 5 This example is very difficult to interpolate. It is essentially defined as a piecewise function, alternating between a straight line and a sinusoidal curve. TEST03 Equally spaced polynomial interpolation. Evaluate the function at N equally spaced points. Determine the N-1 degre polynomial interpolant. Estimate the maximum difference between the function and the interpolant. Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". N Max ||Error|| 1 0.961538 5 0.438134 9 1.04517 13 3.60527 17 14.0515 21 58.2781 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". N Max ||Error|| 1 1 5 0.1472 9 0.315753 13 1.54906 17 10.8772 21 92.6992 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". N Max ||Error|| 1 1 5 0.975672 9 1.3314 13 9.48697 17 88.0671 21 933.226 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". N Max ||Error|| 1 0.7614 5 0.784056 9 0.599198 13 16.0925 17 34.2374 21 476.344 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". N Max ||Error|| 1 1 5 1.7313 9 2.07062 13 5.67344 17 44.8345 21 194.825 TEST04 Bernstein polynomial approximation. Evaluate the function at N equally spaced points. Determine the N-1 degree Bernstein polynomial approximant. Estimate the maximum difference between the function and the approximant. Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". N Max ||Error|| 1 0.961538 5 0.551227 9 0.521209 13 0.464392 17 0.418159 21 0.381911 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". N Max ||Error|| 1 1 5 0.375 9 0.273438 13 0.225586 17 0.196381 21 0.176197 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". N Max ||Error|| 1 1 5 0.672352 9 0.614634 13 0.58547 17 0.566485 21 0.55255 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". N Max ||Error|| 1 0.7614 5 0.518564 9 0.533793 13 0.577633 17 0.521372 21 0.548845 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". N Max ||Error|| 1 1 5 1.68122 9 1.017 13 1.04237 17 1.06321 21 1.0258 TEST05 Linear spline interpolation. Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". N Max ||Error|| 2 0.961538 6 0.5 10 0.235849 14 0.128866 18 0.0796178 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". N Max ||Error|| 2 1 6 0.2 10 0.111111 14 0.0769231 18 0.0588235 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". N Max ||Error|| 2 0.5 6 0.5 10 0.5 14 0.5 18 0.5 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". N Max ||Error|| 2 0.497494 6 0.877526 10 0.822932 14 0.734273 18 0.706998 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". N Max ||Error|| 2 1.95646 6 1.69646 10 1.52669 14 1.09013 18 1.25701 TEST06 Overhauser spline interpolation. Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". X Y * -5 0.0384615 -4.5 0.0460407 * -4 0.0588235 -3.5 0.0744344 * -3 0.1 -2.5 0.133824 * -2 0.2 -1.5 0.325 * -1 0.5 -0.5 0.8 * 0 1 0.5 0.8 * 1 0.5 1.5 0.325 * 2 0.2 2.5 0.133824 * 3 0.1 3.5 0.0744344 * 4 0.0588235 4.5 0.0460407 * 5 0.0384615 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". X Y * -1 1 -0.9 0.9 * -0.8 0.8 -0.7 0.7 * -0.6 0.6 -0.5 0.5 * -0.4 0.4 -0.3 0.3 * -0.2 0.2 -0.1 0.075 * 0 0 0.1 0.075 * 0.2 0.2 0.3 0.3 * 0.4 0.4 0.5 0.5 * 0.6 0.6 0.7 0.7 * 0.8 0.8 0.9 0.9 * 1 1 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". X Y * -1 0 -0.9 0 * -0.8 0 -0.7 0 * -0.6 0 -0.5 0 * -0.4 0 -0.3 -0.0625 * -0.2 0 -0.1 0.5 * 0 1 0.1 1.0625 * 0.2 1 0.3 1 * 0.4 1 0.5 1 * 0.6 1 0.7 1 * 0.8 1 0.9 1 * 1 1 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". X Y * 0 -0 0.05 -0.0475528 * 0.1 -2.64598e-15 0.15 0.213988 * 0.2 0.380423 0.25 0.187471 * 0.3 -3.33067e-16 0.35 0.231767 * 0.4 0.424264 0.45 0.106897 * 0.5 -0.27032 0.55 -0.378142 * 0.6 -0.324862 0.65 -0.0392201 * 0.7 0.269357 0.75 0.384341 * 0.8 0.398294 0.85 0.310854 * 0.9 0.184264 0.95 0.0884112 * 1 0 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". X Y * 0 0 0.5 1.21221 * 1 1.68294 1.5 1.13415 * 2 0.4 2.5 0.407316 * 3 0.6 3.5 0.7 * 4 0.8 4.5 0.925 * 5 1 5.5 0.925 * 6 0.8 6.5 0.605663 * 7 0.6 7.5 1.34903 * 8 1.90938 8.5 1.14903 * 9 0.2 9.5 -0.088673 * 10 0 TEST07 Cubic spline interpolation. Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". X Y * -5 0.0384615 -4.5 0.0470256 * -4 0.0588235 -3.5 0.0748403 * -3 0.1 -2.5 0.140039 * -2 0.2 -1.5 0.297358 * -1 0.5 -0.5 0.820528 * 0 1 0.5 0.820528 * 1 0.5 1.5 0.297358 * 2 0.2 2.5 0.140039 * 3 0.1 3.5 0.0748403 * 4 0.0588235 4.5 0.0470256 * 5 0.0384615 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". X Y * -1 1 -0.9 0.899673 * -0.8 0.8 -0.7 0.700654 * -0.6 0.6 -0.5 0.497712 * -0.4 0.4 -0.3 0.308497 * -0.2 0.2 -0.1 0.0683007 * 0 0 0.1 0.0683007 * 0.2 0.2 0.3 0.308497 * 0.4 0.4 0.5 0.497712 * 0.6 0.6 0.7 0.700654 * 0.8 0.8 0.9 0.899673 * 1 1 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". X Y * -1 0 -0.9 0.00386607 * -0.8 0 -0.7 -0.00773215 * -0.6 0 -0.5 0.0270625 * -0.4 0 -0.3 -0.100518 * -0.2 0 -0.1 0.500009 * 0 1 0.1 1.10048 * 0.2 1 0.3 0.973067 * 0.4 1 0.5 1.00725 * 0.6 1 0.7 0.997928 * 0.8 1 0.9 1.00104 * 1 1 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". X Y * 0 -0 0.05 -0.105534 * 0.1 -2.64598e-15 0.15 0.25862 * 0.2 0.380423 0.25 0.164768 * 0.3 -3.36722e-16 0.35 0.229054 * 0.4 0.424264 0.45 0.152536 * 0.5 -0.27032 0.55 -0.43722 * 0.6 -0.324862 0.65 -0.0281049 * 0.7 0.269357 0.75 0.406058 * 0.8 0.398294 0.85 0.305793 * 0.9 0.184264 0.95 0.0792939 * 1 2.77556e-17 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". X Y * 0 0 0.5 1.37471 * 1 1.68294 1.5 1.0872 * 2 0.4 2.5 0.33995 * 3 0.6 3.5 0.738369 * 4 0.8 4.5 0.906573 * 5 1 5.5 0.98534 * 6 0.8 6.5 0.502068 * 7 0.6 7.5 1.39506 * 8 1.90938 8.5 1.25717 * 9 0.2 9.5 -0.284247 * 10 0 TEST08 B spline approximation. Problem 1 Problem TITLE = "Runge example, f(x) = 1 / ( x * x + 1 ), [-5,5]". X Y * -5 0.0384615 -4.5 0.0490762 * -4 0.0622926 -3.5 0.0810709 * -3 0.109804 -2.5 0.155392 * -2 0.233333 -1.5 0.358333 * -1 0.533333 -0.5 0.733333 * 0 0.833333 0.5 0.733333 * 1 0.533333 1.5 0.358333 * 2 0.233333 2.5 0.155392 * 3 0.109804 3.5 0.0810709 * 4 0.0622926 4.5 0.0490762 * 5 0.0384615 Problem 2 Problem TITLE = "Bernstein example, f(x) = abs ( x ), [-1,1]". X Y * -1 1 -0.9 0.9 * -0.8 0.8 -0.7 0.7 * -0.6 0.6 -0.5 0.5 * -0.4 0.4 -0.3 0.3 * -0.2 0.2 -0.1 0.108333 * 0 0.0666667 0.1 0.108333 * 0.2 0.2 0.3 0.3 * 0.4 0.4 0.5 0.5 * 0.6 0.6 0.7 0.7 * 0.8 0.8 0.9 0.9 * 1 1 Problem 3 Problem TITLE = "Step function, f jumps from 0 to 1 at 0.". X Y * -1 0 -0.9 0 * -0.8 0 -0.7 0 * -0.6 0 -0.5 0 * -0.4 0 -0.3 0.0208333 * -0.2 0.166667 -0.1 0.5 * 0 0.833333 0.1 0.979167 * 0.2 1 0.3 1 * 0.4 1 0.5 1 * 0.6 1 0.7 1 * 0.8 1 0.9 1 * 1 1 Problem 4 Problem TITLE = "Doppler function, highly oscillatory near X = 0.". X Y * 0 0 0.05 0.00792547 * 0.1 0.0634038 0.15 0.182286 * 0.2 0.253615 0.25 0.191125 * 0.3 0.134114 0.35 0.205587 * 0.4 0.237789 0.45 0.0669967 * 0.5 -0.163647 0.55 -0.270741 * 0.6 -0.216736 0.65 -0.0239302 * 0.7 0.19181 0.75 0.316987 * 0.8 0.341133 0.85 0.284754 * 0.9 0.189225 0.95 0.092752 * 1 0 Problem 5 Problem TITLE = "Rabbit ears, f(x) = max(sin(x)+sin(x^2),1-abs(x-5)/5), [0,10]". X Y * 0 0 0.5 0.779682 * 1 1.18863 1.5 1.01058 * 2 0.647157 2.5 0.530895 * 3 0.6 3.5 0.7 * 4 0.8 4.5 0.891667 * 5 0.933333 5.5 0.891667 * 6 0.8 6.5 0.731446 * 7 0.851564 7.5 1.22325 * 8 1.40626 8.5 1.02325 * 9 0.451564 9.5 0.131446 * 10 0 TEST_INTERP_FUN_PRB Normal end of execution. 24 January 2017 03:26:31 PM