If integrating quadratic or cubic polynomials from get-go, the alternative to deriving explicit integral expressions is to use the Simpson rule; it is a deep fact that this method accurately integrates polynomials of degree 3 and lower.
Borrow Mike Graham's example (I haven't used Python after a while, sorry if the code looks elusive):
>>> import numpy >>> p = numpy.poly1d([2, 4, 6]) >>> print p 2 2 x + 4 x + 6 >>> integrand = (1 - 0)(p(0) + 4*p((0 + 1)/2) + p(1))/6
uses the Simpson rule to calculate the integrand value. You can see for yourself that the method works as advertised.
Of course, I did not simplify the expression for integrand to indicate that 0 and 1 can be replaced with arbitrary values โโof u and v , and the code will still work to find the integral of the function from u to v .
user414706
source share