Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Taylor Series
  • Loading branch information
jjv14001 committed Sep 13, 2017
1 parent f6d0b85 commit 7a65efe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions TaylorSeries.py
Expand Up @@ -2,6 +2,7 @@ import sympy as sy
import numpy as np
from sympy.functions import sin,cos
import matplotlib.pyplot as plt
from sympy import E

plt.style.use("ggplot")

Expand All @@ -20,11 +21,17 @@ def factorial(n):
# 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):
def taylor(function,x0,n,a):
i = 0
p = 0
while i <= n:
p = p + (function.diff(x,i).subs(x,x0))/(factorial(i))*(x-x0)**i
i += 1
# u = (M / factorial(n + 1)) * (x - x0)**(n+1)
return p
print(taylor(cos(x),0,5))
e = E.evalf()
print(taylor(e**x,0.5,5,1))
print("Break")
print(taylor(e**x, 0.05,5,0.1))
print("Break")
print(taylor(e**x,0.005,5,0.01))

0 comments on commit 7a65efe

Please sign in to comment.