Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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