Removed duplicated code

master
Per A Brodtkorb 8 years ago
parent 931dfd280b
commit b0d9157308

@ -25,38 +25,43 @@ dea3 = nd.dea3
class PolyBasis(object): class PolyBasis(object):
@staticmethod @staticmethod
def derivative(t, k, n=1): def _derivative(c, m):
c = np.zeros(k + 1) return polynomial.polyder(c, m)
c[k] = 1
dc = polynomial.polyder(c, m=n)
return polynomial.polyval(t, dc)
@staticmethod @staticmethod
def eval(t, c): def eval(t, c):
return polynomial.polyval(t, c) return polynomial.polyval(t, c)
def _coefficients(self, k):
c = np.zeros(k + 1)
c[k] = 1
return c
def derivative(self, t, k, n=1):
c = self._coefficients(k)
dc = self._derivative(c, m=n)
return self.eval(t, dc)
def __call__(self, t, k): def __call__(self, t, k):
return t**k return t**k
poly_basis = PolyBasis() poly_basis = PolyBasis()
class ChebyshevBasis(object): class ChebyshevBasis(PolyBasis):
@staticmethod @staticmethod
def derivative(t, k, n=1): def _derivative(c, m):
c = np.zeros(k + 1)
c[k] = 1
cheb = Chebyshev(c) cheb = Chebyshev(c)
dcheb = cheb.deriv(m=n) dcheb = cheb.deriv(m=m)
return chebval(t, dcheb.coef) return dcheb.coef
@staticmethod @staticmethod
def eval(t, c): def eval(t, c):
return chebval(t, c) return chebval(t, c)
def __call__(self, t, k): def __call__(self, t, k):
c = np.zeros(k + 1) c = self._coefficients(k)
c[k] = 1 return self.eval(t, c)
return chebval(t, c)
chebyshev_basis = ChebyshevBasis() chebyshev_basis = ChebyshevBasis()

Loading…
Cancel
Save