Begin by loading our package for plotting our package that allows symbolic math:
using Plots
using SymPy
This project covers some of the techniques of integration utilizing the symbolic algebra capabilities provide by the SymPy
package.
The basic techniques of integration involve
substitution (reverse chain rule)
integration by parts (reversed product rule)
partial fractions (for rational functions)
The SymPy
function integrate
is a implementation of the Risch Algorithm. This algorithm can decide if a function comprised of elementary functions has an antiderivative expressed in elementary function. For example, neither $\sin(x^2)$ or $e^{x^2}$ has such a "nice" antiderivative, whereas $\sin(x)^2$ and $xe^{-x^2}$ do. Risch's algorithm exploits Liouville's Theorem which gives a representation for any potential antiderivative of $f(x)$ using elementary functions such as polynomials, logarithms, exponentials and trigonometric functions.
integrate
worksuse integrate
to find an antiderivative for
Judging from the answer does it appear to use parts, substitution, both, or something else.
use integrate
to find an antiderivative for
Judging from the answer does it appear to use parts, substitution, both, or something else.
use integrate
to find an antiderivative for
Judging from the answer does it appear to use parts, substitution, both, or something else.
The integrate
function might fail on
But, replacing $\sec(x)$ with $1/\cos(x)$ may work. Does it?
The integrate
function works for many functions, but for some one can help by performing substitutions by hand first.
Here is an example from here where performing the substitution by hand is needed to give a boost. Find
@vars x dx
f(x) = sqrt(x^2 + 1)
u = x*log(x)
ex = f(u) * diff(u,x)
This is written to look like a substitution problem. Will SymPy
be able to see that?
integrate(ex, x)
Sympy can't do this integral, and so returns the expression. We can help.
Let's introduce a variable dx
into our expression, and then we have:
ex = f(u) * diff(u,x) * dx
Then we can have this substitution $u = x\log(x)$ Then $du = (x \cdot \log(x))' dx$.
We replace each $x \log(x)$ with a u
, and replace $dx$ with $dy/(x \cdot \log(x))'$. The subs
function can do so:
u, du = symbols("u, du")
## replace x*log(x) with u and diff(x*log(x),x) * dx with du
ex1 = subs(ex, (x*log(x), u), (dx, du/diff(x*log(x),x)))
This latter function can be integrated (after stripping off the differential we added for familiarity):
ex = integrate(ex1 / du)
If needed we can resubstitute in $x \log(x)$ for $u$ to get an answer.
subs(ex, (u, x*log(x)))
For future use, we codify the above steps in a function:
function usub(ex, let_u_equal)
u, du, dx = symbols("u, du, dx")
ex1 = ex * dx
ex2 = subs(ex1, (dx, du/diff(let_u_equal, x)))
ex3 = subs(ex2, (let_u_equal, u))
ex3 / du
end
usub (generic function with 1 method)
This can be used as follow:
ex = log(x)/x
usub(ex, log(x))
While we are here, we also give this quick function for integration by parts. Just pick "u" and let SymPy
do the ret:
function udv_parts(ex, let_u_equal)
u, dv = let_u_equal, ex/let_u_equal
du = diff(u, x)
v = integrate(dv)
[u*v, v*du] # return two pieces. One for FTC, one to integrate
end
ex = x*sin(x)
uv, vdu = udv_parts(ex, sin(x))
Does integrate
know how to integrate $|x|$?
Assert to SymPy
that $x > 0$ by defining it via:
x = symbols("x", positive=true)
Does integrate
now know how to integrate $|x|$?
What is a simple antiderivative for $\int |x| dx$?
integrate
outDoes integrate
find an antiderivative for
If not, help it out.
The following integral exists, but is not found by integrate
:
Make a $u$-substitution to help integrate
out with finding an answer:
The following integral exists, but is not found by integrate
:
Make a $u$-substitution to help integrate
out with finding an answer:
What do you get if you try a "u"-"dv" integration by parts for $\int e^x \sin(x) dx$? Does it seem to help find the integral?
The LIATE rule is a rule of thumb for identifying what $u$ should be in integrating by parts. Apply it to
What is $u$? What is the "$v \cdot du$" term? Does it seem "easier" than what you started with? Why?
Some background reading on the implementation is here
A rational function is a ratio of polynomial functions. Using polynomial long division and dividing out common factors, up to removable singularities, one can uniquely write a rational function in terms of three other polynomials:
where the degree of $r(x)$ is less than the degree of $q(x)$ and there are no common roots to $r(x)$ and $q(x)$. It is easy to integrate $s(x)$. What about the $r(x)/q(x)$?
We know from the fundamental theorem of algebra that we can factor $q(x) = p_1(x)^n_1 \cdots p_k(x)^{n_k}$, where $p_i$ is a linear or quadratic factor. Further, the partial fraction decomposition ensures then that the ratio can be written as:
with the $a_{ij}(x)$ being polynomials of degree less than or equal the $p_i(x)$, so in this case either a constant or linear polynomial.
So, if the polynomials of the form $(ax+b)/(cx^2 + dx + e)^j$ can be integrated, by the linearity of integration all rational functions can be integrated. Let's investigate this question.
The apart
function separates rational functions into pieces. Use apart
to find the partial fraction decomposition of
Use apart
to find the partial fraction decomposition of
Use apart
to find the partial fraction decomposition of
Use apart
to find the partial fraction decomposition of
Use apart
to find the partial fraction decomposition of
Let $m$ be a positive integer. For which values of $m$ will
will have a rational function for an answer? What is the answer when it isn't a rational function?
What is the integral of a term like:
What is the integral of a term like
For non-negative, integer values of $m$, do these integrals appear to always be rational functions? (Just try some different values starting with $m=1$.)
For non-negative, integer values of $m$, do these integrals appear to always be rational functions?
Verify this is the case for any $m$ by integrating the above symbolically. (You might also try to do the substitution manually.)