>> chebyshev_polynomial_test 25-Apr-2012 08:38:35 CHEBYSHEV_POLYNOMIAL_TEST: MATLAB version. Test the CHEBYSHEV_POLYNOMIAL library. CHEBYSHEV_POLYNOMIAL_TEST01: T_PROJECT_COEFFICIENTS_DATA estimates the Chebyshev polynomial coefficients for a function given as data (x,fx). Here, we use fx = f(x) = x^2 for the data. Since T(0,x) = 1 and T(2,x) = 2*x^2 - 1, the correct expansion is f(x) = 1/2 T(0,x) + 0 T(1,x) + 1/2 T(2,x) + 0 * all other polys. Data ( X, D ): 1: 0.218418 0.0477066 2: 0.956318 0.914543 3: 0.829509 0.688086 4: 0.561695 0.315502 5: 0.415307 0.17248 6: 0.0661187 0.00437169 7: 0.257578 0.0663463 8: 0.109957 0.0120905 9: 0.043829 0.00192098 10: 0.633966 0.401913 11: 0.0617272 0.00381025 12: 0.449539 0.202085 13: 0.401306 0.161047 14: 0.754673 0.569532 15: 0.797287 0.635666 16: 0.00183837 3.37961e-06 17: 0.897504 0.805514 18: 0.350752 0.123027 19: 0.0945448 0.00893871 20: 0.0136169 0.00018542 Coefficients of Chebyshev expansion of degree 4. 1: 0.5 2: -1.00619e-14 3: 0.5 4: -2.96699e-15 I X(I) Data(I) Chebyshev(X(I)) 1 0.218418 0.0477066 0.0477066 2 0.956318 0.914543 0.914543 3 0.829509 0.688086 0.688086 4 0.561695 0.315502 0.315502 5 0.415307 0.17248 0.17248 6 0.0661187 0.00437169 0.00437169 7 0.257578 0.0663463 0.0663463 8 0.109957 0.0120905 0.0120905 9 0.043829 0.00192098 0.00192098 10 0.633966 0.401913 0.401913 11 0.0617272 0.00381025 0.00381025 12 0.449539 0.202085 0.202085 13 0.401306 0.161047 0.161047 14 0.754673 0.569532 0.569532 15 0.797287 0.635666 0.635666 16 0.00183837 3.37961e-06 3.37961e-06 17 0.897504 0.805514 0.805514 18 0.350752 0.123027 0.123027 19 0.0945448 0.00893871 0.00893871 20 0.0136169 0.00018542 0.00018542 CHEBYSHEV_POLYNOMIAL_TEST02 T_POLYNOMIAL_COEFFICIENTS determines the Chebyshev polynomial coefficients. T(0,x) = 1.000000 T(1,x) = 1.000000 * x T(2,x) = 2.000000 * x^2 -1.000000 T(3,x) = 4.000000 * x^3 -3.000000 * x T(4,x) = 8.000000 * x^4 -8.000000 * x^2 1.000000 T(5,x) = 16.000000 * x^5 -20.000000 * x^3 5.000000 * x CHEBYSHEV_POLYNOMIAL_TEST03: T_POLYNOMIAL_VALUES stores values of the Chebyshev polynomials. T_POLYNOMIAL evaluates the polynomial. Tabulated Computed N X T(n,x) T(n,x) Error 0 0.800000 1.0000000000000000e+00 1.0000000000000000e+00 0 1 0.800000 8.0000000000000004e-01 8.0000000000000004e-01 0 2 0.800000 2.8000000000000003e-01 2.8000000000000025e-01 -2.2e-16 3 0.800000 -3.5199999999999998e-01 -3.5199999999999965e-01 -3.3e-16 4 0.800000 -8.4319999999999995e-01 -8.4319999999999973e-01 -2.2e-16 5 0.800000 -9.9712000000000001e-01 -9.9712000000000001e-01 0 6 0.800000 -7.5219199999999997e-01 -7.5219200000000042e-01 4.4e-16 7 0.800000 -2.0638719999999999e-01 -2.0638720000000066e-01 6.7e-16 8 0.800000 4.2197247999999998e-01 4.2197247999999932e-01 6.7e-16 9 0.800000 8.8154316799999999e-01 8.8154316799999966e-01 3.3e-16 10 0.800000 9.8849658880000002e-01 9.8849658880000013e-01 -1.1e-16 11 0.800000 7.0005137409999996e-01 7.0005137408000073e-01 2e-11 12 0.800000 1.3158560969999999e-01 1.3158560972800104e-01 -2.8e-11 CHEBYSHEV_POLYNOMIAL_TEST04: T_POLYNOMIAL_ZEROS computes the zeros of T(n,x); N X T(n,x) 1 0.0000 6.12323e-17 1 0.7071 2.22045e-16 2 -0.7071 -2.22045e-16 1 0.8660 3.33067e-16 2 0.0000 -1.83697e-16 3 -0.8660 -3.33067e-16 1 0.9239 -2.22045e-16 2 0.3827 -2.22045e-16 3 -0.3827 1.11022e-16 4 -0.9239 -2.22045e-16 1 0.9511 -4.44089e-16 2 0.5878 0 3 0.0000 3.06162e-16 4 -0.5878 -7.77156e-16 5 -0.9511 4.44089e-16 CHEBYSHEV_POLYNOMIAL_TEST05: T_QUADRATURE_RULE computes the quadrature rule associated with T(n,x); X W 1: -0.974928 0.448799 2: -0.781831 0.448799 3: -0.433884 0.448799 4: 2.19909e-16 0.448799 5: 0.433884 0.448799 6: 0.781831 0.448799 7: 0.974928 0.448799 Use the quadrature rule to estimate: Q = Integral ( -1 <= X <= +1 ) X^E / sqrt ( 1-x^2) dx E Q_Estimate Q_Exact 0 3.14159 3.14159 1 -5.55112e-17 0 2 1.5708 1.5708 3 -1.11022e-16 0 4 1.1781 1.1781 5 -5.55112e-17 0 6 0.981748 0.981748 7 5.55112e-17 0 8 0.859029 0.859029 9 1.11022e-16 0 10 0.773126 0.773126 11 2.22045e-16 0 12 0.708699 0.708699 13 3.33067e-16 0 CHEBYSHEV_POLYNOMIAL_TEST06: As a sanity check, make sure that the projection of: T(i,x) onto T(j,x) is: 0 if i is not equal to j; pi if i = j = 0; pi/2 if i = j =/= 0. Chebyshev expansion coefficients for T(0,x) 1: 3.14159 2: 7.21645e-16 3: -5.55112e-16 4: -4.44089e-16 Chebyshev expansion coefficients for T(1,x) 1: 7.21645e-16 2: 1.5708 3: 2.22045e-16 4: 3.33067e-16 Chebyshev expansion coefficients for T(2,x) 1: -5.55112e-16 2: 1.11022e-16 3: 1.5708 4: 6.66134e-16 Chebyshev expansion coefficients for T(3,x) 1: -4.44089e-16 2: 3.33067e-16 3: 6.10623e-16 4: 1.5708 CHEBYSHEV_POLYNOMIAL_TEST07: T_PROJECT_COEFFICIENTS computes the Chebyshev coefficients of a function defined over [-1,+1]. T_PROJECT_COEFFICIENTS_AB works in [A,B]. Chebyshev coefficients for exp(x) in [-1,+1] 1: 1.26607 2: 1.13031 3: 0.27145 4: 0.0437939 Chebyshev coefficients for exp(x) in [-1,+1] 1: 1.26607 2: 1.13032 3: 0.271495 4: 0.0443368 5: 0.00547404 6: 0.000539728 Chebyshev coefficients for sin(x) in [-1,+1] 1: 1.85037e-17 2: 0.880101 3: 1.11022e-16 4: -0.0391267 5: 2.77556e-16 6: 0.00050252 Chebyshev coefficients for sin(x) in [-1,+1] 1: 1.85037e-17 2: 0.880101 3: 1.11022e-16 4: -0.0391267 5: 3.14563e-16 6: 0.00050252 Chebyshev coefficients for sqrt(x) in [0,+1] 1: 0.638441 2: 0.420681 3: -0.0808705 4: 0.0318506 5: -0.01484 6: 0.00614694 CHEBYSHEV_POLYNOMIAL_TEST08: T_PROJECT_COEFFICIENTS_DATA computes the Chebyshev coefficients of a function defined by data. We are looking for an approximation that is good in [-1,+1]. Begin by using equally spaced points in [-1,+1]. Chebyshev coefficients for exp(x) on [-1,+1] 1: 1.26667 2: 1.13052 3: 0.271785 4: 0.0443939 Chebyshev coefficients for exp(x) on [-1,+1] 1: 1.26608 2: 1.13032 3: 0.271515 4: 0.0443381 5: 0.00547599 6: 0.000542394 Chebyshev coefficients for sin(x) on [-1,+1] 1: 5.12815e-17 2: 0.880099 3: -3.47596e-17 4: -0.0391279 5: -1.45253e-17 6: 0.000500014 Now sample equally spaced points in [0,+1]. The approximation still applies to the interval [-1,+1]. Chebyshev coefficients for sin(x) on [0,+1] 1: 0.000726991 2: 0.878798 3: 0.000930442 4: -0.0396401 5: 0.00020353 6: 0.000452446 Chebyshev coefficients for sqrt(x) on [0,+1] 1: -14.6903 2: 26.9799 3: -17.4287 4: 8.41285 5: -2.73608 6: 0.463969 Now random points in [-1,+1]. Chebyshev coefficients for sin(x) on [-1,+1] 1: -2.30327e-07 2: 0.880106 3: -8.76709e-07 4: -0.0391223 5: 2.87075e-09 6: 0.000503295 CHEBYSHEV_POLYNOMIAL_TEST09: T_PROJECT_COEFFICIENTS computes the Chebyshev interpolant C(F)(N,X) of a function F(X) defined over [-1,+1]. T_PROJECT_VALUE evaluates that projection. Compute projections of order N to exp(x) over [-1,+1], N Max||F(X)-C(F)(N,X)|| 0 1.718 1 0.3722 2 0.05647 3 0.006657 4 0.0006397 5 5.18e-05 6 3.62e-06 7 2.224e-07 8 1.219e-08 9 6.027e-10 10 2.714e-11 CHEBYSHEV_POLYNOMIAL_TEST10: T_PROJECT_COEFFICIENTS_AB computes the Chebyshev interpolant C(F)(N,X) of a function F(X) defined over [A,B]. T_PROJECT_VALUE_AB evaluates that projection. Compute projections of order N to exp(x) over [0.000000, 1.500000], N Max||F(X)-C(F)(N,X)|| 0 2.365 1 0.3967 2 0.04629 3 0.004159 4 0.0003031 5 1.855e-05 6 9.786e-07 7 4.532e-08 8 1.87e-09 9 6.956e-11 10 2.354e-12 CHEBYSHEV_POLYNOMIAL_TEST11 U_POLYNOMIAL_COEFFICIENTS determines the polynomial coefficients for U(n,x). U(0,x) = 1.000000 U(1,x) = 2.000000 * x U(2,x) = 4.000000 * x^2 -1.000000 U(3,x) = 8.000000 * x^3 -4.000000 * x U(4,x) = 16.000000 * x^4 -12.000000 * x^2 1.000000 U(5,x) = 32.000000 * x^5 -32.000000 * x^3 6.000000 * x CHEBYSHEV_POLYNOMIAL_TEST12: U_POLYNOMIAL_VALUES stores values of the Chebyshev polynomials U(n,x). U_POLYNOMIAL evaluates the polynomial. Tabulated Computed N X U(n,x) U(n,x) Error 0 0.800000 1.0000000000000000e+00 1.0000000000000000e+00 0 1 0.800000 1.6000000000000001e+00 1.6000000000000001e+00 0 2 0.800000 1.5600000000000001e+00 1.5600000000000005e+00 -4.4e-16 3 0.800000 8.9600000000000002e-01 8.9600000000000080e-01 -7.8e-16 4 0.800000 -1.2640000000000001e-01 -1.2639999999999918e-01 -8.3e-16 5 0.800000 -1.0982400000000001e+00 -1.0982399999999994e+00 -6.7e-16 6 0.800000 -1.6307840000000000e+00 -1.6307840000000000e+00 0 7 0.800000 -1.5110144000000001e+00 -1.5110144000000008e+00 6.7e-16 8 0.800000 -7.8683904000000005e-01 -7.8683904000000138e-01 1.3e-15 9 0.800000 2.5207193600000000e-01 2.5207193599999855e-01 1.4e-15 10 0.800000 1.1901541376000000e+00 1.1901541375999991e+00 8.9e-16 11 0.800000 1.6521746841600000e+00 1.6521746841600000e+00 0 12 0.800000 1.4533253570560001e+00 1.4533253570560012e+00 -1.1e-15 CHEBYSHEV_POLYNOMIAL_TEST13: T_POLYNOMIAL_ZEROS computes the zeros of U(n,x); N X U(n,x) 1 0.0000 1.22465e-16 1 0.5000 4.44089e-16 2 -0.5000 -8.88178e-16 1 0.7071 6.66134e-16 2 0.0000 -2.44929e-16 3 -0.7071 6.66134e-16 1 0.8090 0 2 0.3090 -1.11022e-16 3 -0.3090 5.55112e-16 4 -0.8090 -8.88178e-16 1 0.8660 1.33227e-15 2 0.5000 -8.88178e-16 3 0.0000 3.67394e-16 4 -0.5000 -1.77636e-15 5 -0.8660 -1.33227e-15 CHEBYSHEV_POLYNOMIAL_TEST14: U_QUADRATURE_RULE computes the quadrature rule associated with U(n,x); X W 1: -0.92388 0.0575094 2: -0.707107 0.19635 3: -0.382683 0.33519 4: 7.90193e-18 0.392699 5: 0.382683 0.33519 6: 0.707107 0.19635 7: 0.92388 0.0575094 Use the quadrature rule to estimate: Q = Integral ( -1 <= X <= +1 ) X^E * sqrt ( 1-x^2) dx E Q_Estimate Q_Exact 0 1.5708 1.5708 1 5.55112e-17 0 2 0.392699 0.392699 3 -5.55112e-17 0 4 0.19635 0.19635 5 -1.249e-16 0 6 0.122718 0.122718 7 -1.66533e-16 0 8 0.0859029 0.0859029 9 -1.73472e-16 0 10 0.0644272 0.0644272 11 -1.80411e-16 0 12 0.0506214 0.0506214 13 -1.76942e-16 0 CHEBYSHEV_POLYNOMIAL_TEST15: V_POLYNOMIAL_VALUES stores values of the Chebyshev polynomials. V_POLYNOMIAL evaluates the polynomial. Tabulated Computed N X V(n,x) V(n,x) Error 0 0.800000 1.0000000000000000e+00 1.0000000000000000e+00 0 1 0.800000 5.9999999999999998e-01 6.0000000000000009e-01 -1.1e-16 2 0.800000 -4.0000000000000001e-02 -3.9999999999999813e-02 -1.9e-16 3 0.800000 -6.6400000000000003e-01 -6.6399999999999981e-01 -2.2e-16 4 0.800000 -1.0224000000000000e+00 -1.0224000000000000e+00 0 5 0.800000 -9.7184000000000004e-01 -9.7184000000000015e-01 1.1e-16 6 0.800000 -5.3254400000000002e-01 -5.3254400000000035e-01 3.3e-16 7 0.800000 1.1976960000000000e-01 1.1976959999999959e-01 4.2e-16 8 0.800000 7.2417536000000005e-01 7.2417535999999971e-01 3.3e-16 9 0.800000 1.0389109759999999e+00 1.0389109759999999e+00 0 10 0.800000 9.3808220160000000e-01 9.3808220160000022e-01 -2.2e-16 11 0.800000 4.6202054656000002e-01 4.6202054656000047e-01 -4.4e-16 12 0.800000 -1.9884932710400000e-01 -1.9884932710399938e-01 -6.1e-16 CHEBYSHEV_POLYNOMIAL_TEST16: W_POLYNOMIAL_VALUES stores values of the Chebyshev polynomials. W_POLYNOMIAL evaluates the polynomial. Tabulated Computed N X W(n,x) W(n,x) Error 0 0.800000 1.0000000000000000e+00 1.0000000000000000e+00 0 1 0.800000 2.6000000000000001e+00 2.6000000000000001e+00 0 2 0.800000 3.1600000000000001e+00 3.1600000000000001e+00 0 3 0.800000 2.4560000000000000e+00 2.4560000000000008e+00 -8.9e-16 4 0.800000 7.6959999999999995e-01 7.6960000000000139e-01 -1.4e-15 5 0.800000 -1.2246400000000000e+00 -1.2246399999999986e+00 -1.3e-15 6 0.800000 -2.7290239999999999e+00 -2.7290239999999990e+00 -8.9e-16 7 0.800000 -3.1417983999999999e+00 -3.1417984000000003e+00 4.4e-16 8 0.800000 -2.2978534399999999e+00 -2.2978534400000017e+00 1.8e-15 9 0.800000 -5.3476710400000005e-01 -5.3476710400000238e-01 2.3e-15 10 0.800000 1.4422260736000001e+00 1.4422260735999979e+00 2.2e-15 11 0.800000 2.8423288217599998e+00 2.8423288217599989e+00 8.9e-16 12 0.800000 3.1055000412160001e+00 3.1055000412160005e+00 -4.4e-16 CHEBYSHEV_POLYNOMIAL_TEST17: T_TRIPLE_PRODUCT_INTEGRAL computes the triple integral Tijk = integral ( -1 <= x <= 1 ) T(i,x) T(j,x) T(k,x) / sqrt ( 1-x^2) dx I J K Tijk Tijk computed exact 3 3 4 0 -6.27276e-15 4 2 0 0 -4.60743e-15 3 1 0 0 -4.2466e-15 5 1 2 0 -5.55112e-15 4 3 3 0 -6.27276e-15 2 3 1 0.785398 0.785398 2 1 4 0 -3.91354e-15 6 1 0 0 -6.68909e-15 3 3 0 1.5708 1.5708 3 3 1 0 -2.7478e-15 5 2 4 0 -4.38538e-15 4 3 2 0 -3.21965e-15 2 3 1 0.785398 0.785398 2 2 1 0 -1.77636e-15 5 2 1 0 -5.55112e-15 5 1 1 0 -5.66214e-15 6 3 0 0 -4.02456e-15 5 1 3 0 -3.66374e-15 5 1 4 0.785398 0.785398 5 3 2 0.785398 0.785398 CHEBYSHEV_POLYNOMIAL_TEST: Normal end of execution. 25-Apr-2012 08:38:35 >>