From 7a65efe661896f5eaaabb54051ef5f1492a8ca01 Mon Sep 17 00:00:00 2001 From: Jackie Date: Tue, 12 Sep 2017 22:14:52 -0400 Subject: [PATCH] Taylor Series --- TaylorSeries.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TaylorSeries.py b/TaylorSeries.py index f621b99..817f586 100644 --- a/TaylorSeries.py +++ b/TaylorSeries.py @@ -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") @@ -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))