01 November 2011 10:56:04 AM HERMITE_PRB C++ version Test the HERMITE library. TEST01 HERMITE computes the Hermite interpolant to data. Here, f(x) = 1 + 2x + 3x^2. HERMITE_DEMO Compute coefficients CD of the Hermite polynomial interpolant to given data (x,y,yp). Data: X Y Y' 0 0 1 2 1 1 6 8 2 2 17 14 Difference table: XD YD 0 0 1 1 0 2 2 1 3 3 1 0 4 2 0 5 2 0 Hermite interpolating polynomial: p(x) = 3 * x ^ 2 + 2 * x + 1 Data Versus Interpolant: X Y H YP HP 0 0 1 1 2 2 1 1 6 6 8 8 2 2 17 17 14 14 TEST02 HERMITE computes the Hermite interpolant to data. Here, f(x) = 6 + 5x + 4x^2 + 3x^3 + 2x^4 + x^5. HERMITE_DEMO Compute coefficients CD of the Hermite polynomial interpolant to given data (x,y,yp). Data: X Y Y' 0 0 6 5 1 1 21 35 2 2 120 201 Difference table: XD YD 0 0 6 1 0 5 2 1 10 3 1 10 4 2 6 5 2 1 Hermite interpolating polynomial: p(x) = 1 * x ^ 5 + 2 * x ^ 4 + 3 * x ^ 3 + 4 * x ^ 2 + 5 * x + 6 Data Versus Interpolant: X Y H YP HP 0 0 6 6 5 5 1 1 21 21 35 35 2 2 120 120 201 201 TEST03 HERMITE computes the Hermite interpolant to data. Here, f(x) is a fifth order polynomial with random coefficients, and the abscissas are random. Random abscissas 0: 0.218418 1: 0.956318 2: 0.829509 Random polynomial coefficients. 0: 0.561695 1: 0.415307 2: 0.0661187 3: 0.257578 4: 0.109957 5: 0.043829 HERMITE_DEMO Compute coefficients CD of the Hermite polynomial interpolant to given data (x,y,yp). Data: X Y Y' 0 0.218418 0.658516 0.486136 1 0.956318 1.37163 1.81643 2 0.829509 1.16798 1.4115 Difference table: XD YD 0 0.218418 0.658516 1 0.218418 0.486136 2 0.956318 0.650865 3 0.956318 0.679061 4 0.829509 0.249288 5 0.829509 0.043829 Hermite interpolating polynomial: p(x) = 0.043829 * x ^ 5 + 0.109957 * x ^ 4 + 0.257578 * x ^ 3 + 0.0661187 * x ^ 2 + 0.415307 * x + 0.561695 Data Versus Interpolant: X Y H YP HP 0 0.218418 0.658516 0.658516 0.486136 0.486136 1 0.956318 1.37163 1.37163 1.81643 1.81643 2 0.829509 1.16798 1.16798 1.4115 1.4115 TEST04 HERMITE computes the Hermite interpolant to data. Here, f(x) is the Runge function and the data is evaluated at equally spaced points. As N increases, the maximum error grows. N Max | F(X) - H(F(X)) | 3 0.530048 5 0.223403 7 0.390862 9 1.13792 11 3.83581 13 13.9642 15 53.4249 TEST05 HERMITE computes the Hermite interpolant to data. Here, f(x) is the Runge function and the data is evaluated at Chebyshev spaced points. As N increases, the maximum error decreases. N Max | F(X) - H(F(X)) | 3 0.530048 5 0.325238 7 0.180448 9 0.0950617 11 0.0480707 13 0.0237723 15 0.0114442 TEST06: HERMITE_BASIS_0 and HERMITE_BASIS_1 evaluate the Hermite global polynomial basis functions of type 0: associated with function values, and of type 1: associated with derivative values. Interpolate y = x^3 + x^2 + x + 1. XD Y(XD) Y'(XD) 0 1 1 10 1111 321 XV Y(XV) H(XV) 0 1 1 1 4 4 2 15 15 3 40 40 4 85 85 5 156 156 6 259 259 7 400 400 8 585 585 9 820 820 10 1111 1111 TEST07: HERMITE_INTERPOLANT_RULE is given a set of N abscissas for a Hermite interpolant and returns N pairs of quadrature weights for function and derivative values at the abscissas. I X W(F(X)) W(F'(X)) 0 0 -66.6667 -150 1 5 53.3333 -266.667 2 10 23.3333 -33.3333 Use the quadrature rule over interval 0 to 10 Estimate integral of 1 = 10 Estimate integral of X = 50 Estimate integral of X^2 = 333.333 Estimate integral of 1/(1+x^2) = -60.3742 I X W(F(X)) W(F'(X)) 0 0 -6.66667 -1.5 1 0.5 5.33333 -2.66667 2 1 2.33333 -0.333333 Use the quadrature rule over interval 0 to 1 Estimate integral of 1 = 1 Estimate integral of X = 0.5 Estimate integral of X^2 = 0.333333 Estimate integral of 1/(1+x^2) = 0.64 I X W(F(X)) W(F'(X)) 0 0 -2.60271e+10 -4.61959e+09 1 1 -1.2973e+12 -3.74681e+11 2 2 -1.43117e+13 -6.31919e+12 3 3 -5.24034e+13 -3.8283e+13 4 4 -6.11016e+13 -1.01787e+14 5 5 1.53665e+13 -1.29255e+14 6 6 6.73925e+13 -8.01827e+13 7 7 3.82127e+13 -2.36405e+13 8 8 7.64733e+12 -3.02886e+12 9 9 5.13565e+11 -1.37316e+11 10 10 7.52948e+09 -1.26888e+09 Use the quadrature rule over interval 0 to 10 Estimate integral of 1 = 9.98964 Estimate integral of X = 49.7728 Estimate integral of X^2 = 331.017 Estimate integral of 1/(1+x^2) = 1.26716e+09 I X W(F(X)) W(F'(X)) 0 0 -2.60271e+09 -4.61959e+07 1 0.1 -1.2973e+11 -3.74681e+09 2 0.2 -1.43117e+12 -6.31919e+10 3 0.3 -5.24034e+12 -3.8283e+11 4 0.4 -6.11016e+12 -1.01787e+12 5 0.5 1.53665e+12 -1.29255e+12 6 0.6 6.73925e+12 -8.01827e+11 7 0.7 3.82127e+12 -2.36405e+11 8 0.8 7.64733e+11 -3.02886e+10 9 0.9 5.13565e+10 -1.37316e+09 10 1 7.52948e+08 -1.26888e+07 Use the quadrature rule over interval 0 to 1 Estimate integral of 1 = 0.999183 Estimate integral of X = 0.50165 Estimate integral of X^2 = 0.334203 Estimate integral of 1/(1+x^2) = 0.638341 I X W(F(X)) W(F'(X)) 0 0 -3.06432e+11 -2.33178e+09 1 0.0244717 1.96461e+11 -8.7651e+09 2 0.0954915 5.13319e+10 -7.40794e+09 3 0.206107 2.18086e+10 -5.89147e+09 4 0.345492 1.04125e+10 -4.63078e+09 5 0.5 4.78847e+09 -3.7192e+09 6 0.654508 1.24726e+09 -3.09863e+09 7 0.793893 -2.27985e+09 -2.69011e+09 8 0.904508 -9.30372e+09 -2.43423e+09 9 0.975528 -4.38263e+10 -2.29381e+09 10 1 7.57919e+10 -5.62265e+08 Use the quadrature rule over interval 0 to 1 Estimate integral of 1 = 0.999954 Estimate integral of X = 0.499973 Estimate integral of X^2 = 0.33332 Estimate integral of SIN(X) = 0.45968 TEST08 HERMITE_INTERPOLANT sets up the Hermite interpolant. HERMITE_INTERPOLANT_VALUE evaluates it. Consider data for y=sin(x) at x=0,1,2,3,4. In the following table, there should be perfect agreement between F and H, and F' and H' at the data points X = 0, 1, 2, 3, and 4. In between, H and H' approximate F and F'. I X(I) F(X(I)) H(X(I)) F'(X(I)) H'(X(I)) 0 0 0 0 1 1 1 0.25 0.247404 0.247407 0.968912 0.968921 2 0.5 0.479426 0.479428 0.877583 0.877575 3 0.75 0.681639 0.681639 0.731689 0.731683 4 1 0.841471 0.841471 0.540302 0.540302 5 1.25 0.948985 0.948985 0.315322 0.315324 6 1.5 0.997495 0.997495 0.0707372 0.0707368 7 1.75 0.983986 0.983986 -0.178246 -0.178247 8 2 0.909297 0.909297 -0.416147 -0.416147 9 2.25 0.778073 0.778073 -0.628174 -0.628172 10 2.5 0.598472 0.598473 -0.801144 -0.801143 11 2.75 0.381661 0.381661 -0.924302 -0.924304 12 3 0.14112 0.14112 -0.989992 -0.989992 13 3.25 -0.108195 -0.108194 -0.99413 -0.994124 14 3.5 -0.350783 -0.350781 -0.936457 -0.936451 15 3.75 -0.571561 -0.571559 -0.820559 -0.820567 16 4 -0.756802 -0.756802 -0.653644 -0.653644 HERMITE_PRB Normal end of execution. 01 November 2011 10:56:04 AM