def roots(self, use_2nd=True): if use_2nd: cs = flipud(chebt2(self.Ys)) roots = chebroots(cs) reals = abs(imag(roots)) < params.interpolation.convergence.abstol roots = real(roots[reals]) unit = (roots>-1.0) & (roots < 1.0) roots = roots[unit] return (roots*(self.Xs[-1]-self.Xs[0])+(self.Xs[0]+self.Xs[-1]))*0.5 else: Ys = self.interp_at(chebspace(self.Xs[0], self.Xs[-1], self.n)) cs = flipud(chebt2(Ys)) roots = chebroots(cs) reals = abs(imag(roots)) < params.interpolation.convergence.abstol roots = real(roots[reals]) unit = (roots>-1.0) & (roots < 1.0) roots = roots[unit] return (roots*(self.Xs[-1]-self.Xs[0])+(self.Xs[0]+self.Xs[-1]))*0.5
def trim(self, abstol=None): c = chebt2(self.Ys) if abstol is None: abstol = params.interpolation.convergence.abstol while c[0] < abstol: c = c[1:] Ydiffvals = ichebt2(c) Ydiffvals = flipud(Ydiffvals) Xs, Ws = chebspace(self.a, self.b, len(Ydiffvals), returnWeights=True) f = BarycentricInterpolator(Xs, Ydiffvals, Ws) return f
def diff(self, use_2nd=True): if use_2nd: c = chebt2(self.Ys) n = len(c); cdiff = zeros(n + 1); v = concatenate(([0, 0], 2 * arange(n - 1, 0, -1) * c[0:-1])); cdiff[0::2] = cumsum(v[0::2]); cdiff[1::2] = cumsum(v[1::2]); cdiff[-1] = .5 * cdiff[-1]; cdiff = cdiff[2:]; Ydiffvals = ichebt2(cdiff) / ((self.Xs[-1] - self.Xs[0]) * 0.5) Ydiffvals = flipud(Ydiffvals) Xs, Ws = chebspace(self.Xs[0], self.Xs[-1], len(Ydiffvals), returnWeights=True) f = BarycentricInterpolator(Xs, Ydiffvals, Ws) return f else: Xs, Ws = chebspace(self.Xs[0], self.Xs[-1], len(self.Xs)+2, returnWeights=True) Ys = self.interp_at(Xs) return BarycentricInterpolator(Xs, Ys, Ws).diff(use_2nd=True)