-
-
Save anthonymorast/c549e7c84091c87fe55baf37d0597cea to your computer and use it in GitHub Desktop.
coefficients.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.misc import derivative | |
import math | |
class TaylorSeries(): | |
def __init__(self, function, order, center=0): | |
self.center = center | |
self.f = function | |
self.order = order | |
self.d_pts = order*2 | |
self.coefficients = [] | |
# number of points (order) for scipy.misc.derivative | |
if self.d_pts % 2 == 0: # must be odd and greater than derivative order | |
self.d_pts += 1 | |
self.__find_coefficients() | |
def __find_coefficients(self): | |
for i in range(0, self.order+1): | |
self.coefficients.append(round(derivative(self.f, self.center, n=i, order=self.d_pts)/math.factorial(i), 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment