Skip to content

Instantly share code, notes, and snippets.

@anthonymorast
Created October 3, 2021 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonymorast/8699e1aa1990cfcbf179cb15650514c7 to your computer and use it in GitHub Desktop.
Save anthonymorast/8699e1aa1990cfcbf179cb15650514c7 to your computer and use it in GitHub Desktop.
def approximate_integral(self, x0, x1):
"""
Estimates the definite integral of the function using the Taylor series expansion.
x0 - lower limit of integration
x1 - upper limit of integration
"""
# integrals can be off by a constant since int(f(x)) = F(x) + C
value = 0
for i in range(len(self.coefficients)):
value += ((self.coefficients[i] * (1/(i+1)) * ((x1 - self.center)**(i+1))) -
(self.coefficients[i] * (1/(i+1)) * ((x0 - self.center)**(i+1)))) # integrate each term: x^n => (1/n+1)*x^(n+1)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment