Skip to content

Commit

Permalink
Taylor Series Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jjv14001 committed Sep 12, 2017
1 parent 2dda885 commit 38552bf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion TaylorSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ def factorial(n):
return n*factorial(n-1)

# Taylor approximation at x0 of the function 'function'
# Since I'm still having difficulting getting this to work, I can just create individual functions for each equation (since I don't need the whole thing).
#Make sure you create a function estimating the upper bound error

def taylor(function,x0,n):
i = 0
p = 0
while i <= n:
p = p + (function.diff(x,i).subs(x,x0))/(factorial(i))*(x-x0)**i
i += 1
return p
print(taylor(cos(x),0,5))
def plot():
x_lims = [-5,5]
x1 = np.linspace(x_lims[0],x_lims[1],800)
Expand All @@ -47,4 +51,4 @@ def plot():
plt.title('Taylor series approximation')
plt.show()

plot()
#plot()

0 comments on commit 38552bf

Please sign in to comment.