Integrating Polynomials#
When we are differentiating \(x^n\), we multiply by \(n\) and then reduce the power on \(x\) by 1. When integrating, we do the opposite, we add 1 to the power and then divide by this new power. In general, we have the rule:
Example
Find the integrals of the following:
\(x^2\)
\(2x+6x^2\)
\(x(x+3)\)
Solution:
We are being asked to find \(\int x^2\;dx\), so using the rule \(\int n^n\;dx = \frac{x^{n+1}}{n+1} + C\)
\[ \int x^2\;dx = \frac{x^{2+1}}{2+1} + C = \frac{x^3}{3} + C \]We are being asked to find \(\int (2x + 6x^2) \;dx\). When integrating mulitple terms, we do each of them one in turn. This means that:
\[\begin{split} \begin{aligned} \int(2x+6x^2)\;dx & = \int 2x\;dx + \int 6x^2\;dx \\ & 2\int x\;dx + 6\int x\;dx \\ & 2\frac{x^{1+1}}{1+1} + 6\frac{x^{2+1}}{2+1} + C \\ & = x^2 + 2x^3 + C \end{aligned} \end{split}\]First, we expand the brackets to produce \(x^2 + 3x\). Then we would integrat this to give:
\[ \int(x^2+3x)\;dx = \frac{x^{2+1}}{2+1} + 3\frac{x^{1+1}}{1+1} + C = \frac{1}{3}x^3 + \frac{3}{2}x^2 + C \]
Similar to differentiation, the sympy library can be used to perform symbolic integration, using the integrate function.
from sympy import symbols, integrate
x = symbols('x')
integrate(x**2)
integrate(2 * x + 6 * x ** 2)
integrate(x * (x + 3))
Be aware, that sympy drops the \(+C\) from the result of these integrations.
Integrating \(x^{-1}\)#
We recall that if we differentiate \(\ln(x)\), we get \(x^{-1}\). Since integration is the opposite of differentiation, when we integrate \(x^{-1}\), we get \(\ln(x)\).
Example
Find the following integral:
Solution: The fraction can be simplified, by dividing each term on the denominator by \(x^3\). This reduces the original integral into:
Again, this is straightforward for sympy.
integrate((x ** 2 + 2 * x ** 3 - 4 * x ** 4) / (x ** 3))