|
| 1 | +"""Chebyshev polynomials of the first kind.""" |
| 2 | +import numpy |
| 3 | +import chaospy |
| 4 | + |
| 5 | + |
| 6 | +def chebyshev_1( |
| 7 | + order, |
| 8 | + lower=-1, |
| 9 | + upper=1, |
| 10 | + physicist=False, |
| 11 | + normed=False, |
| 12 | + retall=False, |
| 13 | +): |
| 14 | + """ |
| 15 | + Chebyshev polynomials of the first kind. |
| 16 | +
|
| 17 | + Args: |
| 18 | + order (int): |
| 19 | + The polynomial order. |
| 20 | + lower (float): |
| 21 | + Lower bound for the integration interval. |
| 22 | + upper (float): |
| 23 | + Upper bound for the integration interval. |
| 24 | + physicist (bool): |
| 25 | + Use physicist weights instead of probabilist. |
| 26 | +
|
| 27 | + Returns: |
| 28 | + (numpoly.ndpoly, numpy.ndarray): |
| 29 | + Chebyshev polynomial expansion. Norms of the orthogonal |
| 30 | + expansion on the form ``E(orth**2, dist)``. |
| 31 | +
|
| 32 | + Examples: |
| 33 | + >>> polynomials, norms = chaospy.expansion.chebyshev_1(4, retall=True) |
| 34 | + >>> polynomials |
| 35 | + polynomial([1.0, q0, q0**2-0.5, q0**3-0.75*q0, q0**4-q0**2+0.125]) |
| 36 | + >>> norms |
| 37 | + array([1. , 0.5 , 0.125 , 0.03125 , 0.0078125]) |
| 38 | + >>> chaospy.expansion.chebyshev_1(3, physicist=True) |
| 39 | + polynomial([1.0, q0, 2.0*q0**2-1.0, 4.0*q0**3-2.5*q0]) |
| 40 | + >>> chaospy.expansion.chebyshev_1(3, lower=0.5, upper=1.5, normed=True).round(3) |
| 41 | + polynomial([1.0, 2.828*q0-2.828, 11.314*q0**2-22.627*q0+9.899, |
| 42 | + 45.255*q0**3-135.765*q0**2+127.279*q0-36.77]) |
| 43 | +
|
| 44 | + """ |
| 45 | + multiplier = 1+numpy.arange(order).astype(bool) if physicist else 1 |
| 46 | + _, [polynomials], [norms] = chaospy.recurrence.analytical_stieltjes( |
| 47 | + order, chaospy.Beta(0.5, 0.5, lower, upper), multiplier=multiplier) |
| 48 | + if normed: |
| 49 | + polynomials = chaospy.true_divide(polynomials, numpy.sqrt(norms)) |
| 50 | + norms[:] = 1. |
| 51 | + return (polynomials, norms) if retall else polynomials |
| 52 | + |
| 53 | + |
| 54 | +def chebyshev_2( |
| 55 | + order, |
| 56 | + lower=-1, |
| 57 | + upper=1, |
| 58 | + physicist=False, |
| 59 | + normed=False, |
| 60 | + retall=False, |
| 61 | +): |
| 62 | + """ |
| 63 | + Chebyshev polynomials of the second kind. |
| 64 | +
|
| 65 | + Args: |
| 66 | + order (int): |
| 67 | + The quadrature order. |
| 68 | + lower (float): |
| 69 | + Lower bound for the integration interval. |
| 70 | + upper (float): |
| 71 | + Upper bound for the integration interval. |
| 72 | + physicist (bool): |
| 73 | + Use physicist weights instead of probabilist. |
| 74 | +
|
| 75 | + Returns: |
| 76 | + (numpoly.ndpoly, numpy.ndarray): |
| 77 | + Chebyshev polynomial expansion. Norms of the orthogonal |
| 78 | + expansion on the form ``E(orth**2, dist)``. |
| 79 | +
|
| 80 | + Examples: |
| 81 | + >>> polynomials, norms = chaospy.expansion.chebyshev_2(4, retall=True) |
| 82 | + >>> polynomials |
| 83 | + polynomial([1.0, q0, q0**2-0.25, q0**3-0.5*q0, q0**4-0.75*q0**2+0.0625]) |
| 84 | + >>> norms |
| 85 | + array([1. , 0.25 , 0.0625 , 0.015625 , 0.00390625]) |
| 86 | + >>> chaospy.expansion.chebyshev_2(3, physicist=True) |
| 87 | + polynomial([1.0, 2.0*q0, 4.0*q0**2-0.5, 8.0*q0**3-2.0*q0]) |
| 88 | + >>> chaospy.expansion.chebyshev_2(3, lower=0.5, upper=1.5, normed=True).round(3) |
| 89 | + polynomial([1.0, 4.0*q0-4.0, 16.0*q0**2-32.0*q0+15.0, |
| 90 | + 64.0*q0**3-192.0*q0**2+184.0*q0-56.0]) |
| 91 | +
|
| 92 | + """ |
| 93 | + multiplier = 2 if physicist else 1 |
| 94 | + _, [polynomials], [norms] = chaospy.recurrence.analytical_stieltjes( |
| 95 | + order, chaospy.Beta(1.5, 1.5, lower, upper), multiplier=multiplier) |
| 96 | + if normed: |
| 97 | + polynomials= chaospy.true_divide(polynomials, numpy.sqrt(norms)) |
| 98 | + norms[:] = 1. |
| 99 | + return (polynomials, norms) if retall else polynomials |
0 commit comments