def _create_Tderiv(self, k, n): r"""Create the n'th derivative of the k'th Chebyshev polynomial.""" if not self._use_mp: return ChebyshevT.basis(k).deriv(n) else: if n == 0: return lambda x: mp.chebyt(k, x) # Since the Chebyshev derivatives attain high values near the # borders +-1 and usually are subtracted to obtain small values, # minimizing their relative error (i.e. fixing the number of # correct decimal places (dps)) is not enough to get precise # results. Hence, the below `moredps` variable is set to higher # values close to the border. extradps = 5 pos = mp.fprod( [mp.mpf(k**2 - p**2) / (2 * p + 1) for p in range(n)]) neg = (-1)**(k + n) * pos if n == 1: def dTk(x): with mp.extradps(extradps): x = clip(x, -1.0, 1.0) if mp.almosteq(x, mp.one): return pos if mp.almosteq(x, -mp.one): return neg moredps = max( 0, int(-math.log10( min(abs(x - mp.one), abs(x + mp.one))) / 2)) moredps = min(moredps, 100) with mp.extradps(moredps): t = mp.acos(x) return k * mp.sin(k * t) / mp.sin(t) return dTk if n == 2: def ddTk(x): with mp.extradps(extradps): x = clip(x, -1.0, 1.0) if mp.almosteq(x, mp.one): return pos if mp.almosteq(x, -mp.one): return neg moredps = max( 0, int(-math.log10( min(abs(x - mp.one), abs(x + mp.one))) * 1.5) + 2) moredps = min(moredps, 100) with mp.extradps(moredps): t = mp.acos(x) s = mp.sin(t) return -k**2 * mp.cos(k * t) / s**2 + k * mp.cos( t) * mp.sin(k * t) / s**3 return ddTk raise NotImplementedError( 'Derivatives of order > 2 not implemented.')
def Prod(A): assert (len(A) > 0) return mp.fprod(A)
def Prod(A): assert(len(A) > 0) return mp.fprod(A)