Skip to content

Instantly share code, notes, and snippets.

@anthonymorast
Created Oct 3, 2021
Embed
What would you like to do?
from TaylorSeries import TaylorSeries
import math
def f(x):
return math.cos(x) #(math.e**x)*math.sin(x)*math.cos(x)
if __name__ == '__main__':
pts = [0, math.pi/6, math.pi/4, math.pi/3, math.pi/2, math.pi]
# pts = [-5, -4, -3, -2, -1, -0.1, 0, 0.1, 1, 2, 3, 4, 5]
terms = 15
center = 0
precision = 3
ts = TaylorSeries(f, terms, center)
ts.print_coefficients()
ts.print_equation()
print("x\tf(x)\tApprox. f(x)\tIntegral f(x)\tDerivative f(x)")
for x in pts:
print("{:.3f}\t{:.3f}\t{:.3f}\t{:.3f}\t{:.3f}".format(x, f(x), ts.approximate_value(x), ts.approximate_integral(0, x), ts.approximate_derivative(x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment