% This is lecture no. 11 of MH1101/: Calculus II.

\chapter[Integrating Polynomial Fractions]{Partial Fractions \& Inverse Trigonometric Substitution}%
\label{cha:partial_fractions_&_inverse_trigonometric_substitution}

\section{Partial Fractions for Integration of Rational Functions}%
\label{sec:partial_fractions_for_integration_of_rational_functions}

Now we consider integrals such as:
\[
	\int \frac{x^3+3x^2}{x^2+1}\ud x\quad \int \frac{2+3x+x^2}{x(x^2+1)}\ud x
,\]
or, in general, integrals of the form:
\[
	\int \frac{P(x)}{Q(x)}\ud x
,\]
where $P$ and $Q$ are polynomials.
This is done by  \textbf{partial fractions}.
First we check if the integrand is proper, that is, $\textrm{deg}(P(x))<\textrm{deg}(Q(x))$.
If it is not, do long division to divide $P(x)$ by $Q(x)$ until the remainder $R(x)$ has a degree lesser than $Q(x)$:
\[
	\int \frac{P(x)}{Q(x)}\ud x = \int s(x) + \frac{R(x)}{Q(x)}\ud x
.\]
Then, we factorise the denominator $Q(x)$ as a product of linear and irreducible quadratic factors.
We express the proper rational function $\frac{R(x)}{Q(x)}$ as a sum of partial fractions of the form:
\[
	\frac{A}{(ax+b)^{k}}\quad \textrm{or} \quad \frac{Ax+B}{(ax^2+bx+c)^{k}}
.\]

\subsection{Linear Factors}%
\label{sub:linear_factors}

If the denominator is a product of distinct linear factors, then the corresponding partial fraction representation for each factor $ax+b$ is $\frac{A}{ax+b}$.
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{x+2}{x(x-1)(x+1)}\ud x}$.
	\begin{sol}
		There are three distinct linear factors, the corresponding partial fractions are:
		\[
		\frac{A}{x},\ \frac{B}{x-1},\ \frac{C}{x+1}
		.\]
		Thus, we shall solve for constants $A$, $B$, and $C$ such that:
		\begin{align*}
			\frac{x+2}{x(x-1)(x+1)} & =\frac{A}{x}+\frac{B}{x-1}+\frac{C}{x+1}\\
						& = \frac{A(x+1)(x-1)+Bx(x+1)+Cx(x-1)}{x(x-1)(x+1)}.
		\end{align*}
		Comparing coefficients in the numerator, we get the following simultaneous equations:
		\begin{align*}
			A + B + C & = 0\\
			B-C& = 1\\
			-A & = 2
		\end{align*}
		The solutions of which are:
		\[
		A=-2,\ B=\frac{3}{2},\ C=\frac{1}{2}
		.\]
		Thus we have:
		\begin{align*}
			\int \frac{x+2}{x(x-1)(x+1)}\ud x & = \int -\frac{2}{x}+\frac{3/2}{x-1} + \frac{1/2}{x+1}\ud x\\
							  & = -2\int \frac{1}{x}\ud x + \frac{3}{2}\int \frac{1}{x-1}\ud x + \frac{1}{2}\int \frac{1}{x+1}\ud x\\
							  & = -2\ln|x|+\frac{3}{2}\ln|x-1|+\frac{1}{2}\ln|x+1|+C.
		\end{align*}
	\end{sol}
\end{exmp}

If $Q(x)$ is a product of linear factors, some of which are \textbf{repeated}, say $(ax+b)^{k}$, where $k\geqslant 2$, then there are $k$ corresponding partial fractions:
\[
	\frac{A_1}{ax+b},\ \frac{A_2}{(ax+b)^2},\dotsc, \frac{A_{k-1}}{(ax+b)^{k-1}},\ \frac{A_{k}}{(ax+b)^{k}}
.\]
\begin{exmp}
	Evaluate $\displaystyle{\int\frac{x^2}{(x-3)(x+2)^2}\ud x}$.
	\begin{sol}
		For $(x-3)$, the corresponding partial fraction is $\displaystyle{\frac{A}{x-3}}$.
		For $(x+2)^2$, the corresponding partial fractions are:
		\[
			\frac{B}{x+2}+\frac{C}{(x+2)^2}
		.\]
		Next we find constants $A$, $B$, and $C$ such that:
		\begin{align*}
			\frac{x^2}{(x-3)(x+2)^2} & = \frac{A}{x-3}+\frac{B}{x+2}+\frac{C}{(x+2)^2}\\
						 & = \frac{A(x+2)^2+B(x-3)(x+2)+C(x-3)}{(x-3)(x+2)^2}.
		\end{align*}
		Comparing coefficients we get:
		\begin{align*}
			A+B&=1\\
			4A-B+C&=0\\
			4A-6B-3C&=0
		\end{align*}
		The solutions of which are:
		\[
		A=\frac{9}{25},\ B=\frac{16}{25},\ C=-\frac{4}{5}
		.\]
		Thus we have:
		\begin{align*}
			\int \frac{x^2}{(x-3)(x+2)^2}\ud x&= \frac{1}{25}\int \frac{9}{x-3}+\frac{16}{x+2}-\frac{20}{(x+2)^2}\ud x\\
							  & = \frac{9}{25}\int \frac{1}{x-3}\ud x + \frac{16}{25}\int \frac{1}{x+2}\ud x-\frac{20}{25}\int \frac{1}{(x+2)^2}\ud x\\
							  & = \frac{1}{25}\left(9\ln|x-3| + 16\ln|x+2|+\frac{20}{x+2}\right)+C.
		\end{align*}
	\end{sol}
\end{exmp}

\subsection{Irreducible Quadratic Factors}%
\label{sub:irreducible_quadratic_factors}

The quadratic expression $ax^2+bx+c$ is said to be irreducible when it cannot be reduced to a product of linear factors.
In this case we have $b^2-4ac<0$.
We can therefore express the quadratic expression in the form $(Ax + B)^2 + D^2$, via completing the square.
\[
	f(x) = \frac{P(x)}{Q(x)}
.\]
Suppose $Q(x)$ contains the irreducible quadratic factor $ax^2+bx+c$.
Then the partial fraction representation of $f(x)$ will contain the term:
\[
\frac{Ax+B}{ax^2+bx+c}
.\]
In this case, we have the useful standard integral:
\[
\int \frac{1}{a^2 + x^2}\ud x = \frac{1}{a}\tan^{-1}\frac{x}{a}+C
.\]
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{1}{x^2+4x+5x}\ud x}$.
	\begin{sol}
		The quadratic expression $x^2+4x+5$ is irreducible as its discriminant is less than 0.
		We first complete the square to obtain:
		\[
			x^2+4x+5=(x+2)^2+1
		.\]
		Thus we have:
		\[
			\int \frac{1}{x^2+4x+5}\ud x = \int \frac{1}{(x+2)^2+1}\ud x
		.\]
		We then use the substitution $u(x)=x+2$, $\therefore u^{\prime}(x)=1$:
		\begin{align*}
			\int \frac{1}{x^2+4x+5}\ud x & = \int \frac{1}{(x+2)^2+1}\ud x\\
						     & = \int \frac{1}{u^2+1}\ud u\\
						     & = \tan^{-1}u+C\\
						     & = \tan^{-1}(x+2)+C.
		\end{align*}
	\end{sol}
\end{exmp}
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{1}{4x^2+4x+26}\ud x}$.
	\begin{sol}
		Completing the square we have:
		\[
			4x^2+4x+26 = (2x+1)^2+5^2
		.\]
		Therefore we have:
		\begin{align*}
			\int \frac{1}{4x^2+4x+26}\ud x & = \int \frac{1}{(2x+1)^2+5^2}\ud x\\
			\intertext{Substituting $u(x)=2x+1$, $\therefore u^{\prime}(x)=2$:}
						       & = \frac{1}{2}\int \frac{1}{u^2+5^2}\ud u\\
						       & = \frac{1}{2}\left(\frac{1}{5}\tan^{-1}\left(\frac{u}{5}\right)\right)+C\\
						       & = \frac{1}{10}\tan^{-1}\frac{2x+1}{5}+C.
		\end{align*}
	\end{sol}
\end{exmp}
Another useful standard integral to use in cases where there are irreducible quadratic factors:
\[
	\int \frac{f^{\prime}(x)}{f(x)}=\ln |f(x)|+C
.\]
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{x}{x^2+4x+13}\ud x}$.
	\begin{sol}
		We can see that $x^2+4x+13$ is irreducible, so we complete the square:
		\[
			x^2+4x+13 = (x+2)^2+9
		.\]
		Now we express in terms of partial fractions:
		\[
			\frac{x}{x^2+4x+13} = \underbrace{\frac{A(2x+4)}{x^2+4x+13}}_{\frac{Af^{\prime}(x)}{f(x)}} + \frac{B}{x^2+4x+13}
		.\]
		Which gives $A=\frac{1}{2}$ and $B=-2$.
		Therefore we have:
		\begin{align*}
			\int \frac{x}{x^2+4x+13}\ud x & = \frac{1}{2}\int \frac{2x+4}{x^2+4x+13}\ud x-2\int \frac{1}{x^2+4x+13}\ud x\\
						      & = \frac{1}{2}\ln|x^2+4x+13| -2\left(\frac{1}{3}\tan^{-1}\frac{x+2}{3}\right)+C\\
						      & = \frac{1}{2}\ln|x^2+4x+13|-\frac{2}{3}\tan^{-1}\frac{x+2}{3}+C.
		\end{align*}
	\end{sol}
\end{exmp}
Suppose $Q(x)$ contains the repeating irreducible quadratic factors $(ax^2+bx+c)^{k}$.
Then the partial fraction representation of $f(x)$ will contain the terms:
\[
	\frac{A_{i}x+B_{i}}{(ax^2+bx+c)^{i}},\ \forall i = 1,2,3,\dotsc,k
.\]
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{x^2}{x(x^2+4)^3}\ud x}$.
	\begin{sol}
		We break the fraction into its partial fractions:
		\[
			\frac{x^2}{x(x^2+4)^3}=\frac{A}{x}+\frac{A_1x+B_1}{x^2+4}+\frac{A_2x+B_2}{(x^2+4)^2}+\frac{A_3x+B_3}{(x^2+4)^3}
		.\]
		Then, we proceed like the previous examples to solve for the unknowns.
	\end{sol}
\end{exmp}

\section{Inverse Trigonometric Substitution}%
\label{sec:inverse_trigonometric_substitution}

\subsection{Integrands Involving $\sqrt{a^2+x^2}$ or $a^2+x^2$}%
\label{sub:integrands_involving_a^2+x^2_or_a_2_x_2_}

For the inverse substitution, we use $x=a\tan\theta$ instead of the equivalent $\theta = \tan^{-1}\frac{x}{a}$.
This is usually useful because:
\[
	a^2+x^2 = a^2 + a^2\tan^2\theta = a^2(1+\tan^2\theta) = a^2\sec^2\theta
.\]
And:
\[
\frac{\upd x}{\upd \theta}=a\sec^2\theta
.\]
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{1}{\sqrt{a^2+x^2}}\ud x}$, where $a>0$.
	\begin{sol}
		Let $x=a\tan\theta$ so that $\displaystyle{\frac{\upd x}{\upd \theta}=a\sec^2\theta}$, and
		\[
		\sqrt{a^2+x^2}=\sqrt{a^2+a^2\tan^2\theta}=a\sec\theta
		.\]
		Thus we have:
		\begin{align*}
			\int \frac{1}{\sqrt{a^2+x^2}}\ud x & = \int \frac{1}{a\sec\theta}(a\sec^2\theta)\ud \theta\\
							   & = \int\sec\theta\ud\theta\\
							   & = \ln|\sec\theta+\tan\theta|+C\\
							   & = \ln\left\lvert \frac{\sqrt{a^2+x^2}}{a}+\frac{x}{a}\right\rvert + C.
		\end{align*}
	\end{sol}
\end{exmp}
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{1}{(4+x^2)^2}\ud x}$.
	\begin{sol}
		This type of integral is often seen in the last case of integration by partial fractions.
		Let $x=2\tan u$.
		Then $\displaystyle{\frac{\upd x}{\upd u}=2\sec^2u}$:
		\begin{align*}
			\int \frac{1}{(4+x^2)^2}\ud x & = \int \frac{1}{(4\sec^2u)^2}(2\sec^2u)\ud u\\
						      & = \frac{1}{8}\int \frac{1}{\sec^2u}\ud u\\
						      & = \frac{1}{8}\int\cos^2u\ud u\\
						      & = \frac{1}{8}\int \left(\frac{\cos(2u)+1}{2}\right)\ud u\\
						      & = \frac{1}{16}\left(\frac{\sin(2u)}{2}+u\right)+C.
		\end{align*}
		From $u=\tan^{-1}\frac{x}{2}$, we have:
		\[
			\tan u = \frac{x}{2},\ \sin u = \frac{x}{\sqrt{4+x^2}},\ \cos u = \frac{2}{\sqrt{4+x^2}}
		,\]
		so that:
		\begin{align*}
			\frac{\sin(2u)}{2} & = \sin u\cos u\\
					   & = \frac{2x}{4+x^2}.
		\end{align*}
		Therefore we have:
		\[
			\int \frac{1}{(4+x^2)^2}\ud x = \frac{1}{16}\left(\frac{2x}{4+x^2}+\tan^{-1}\left(\frac{x}{2}\right)\right)+C
		.\]
	\end{sol}
\end{exmp}

\subsection{Integrands Involving $\sqrt{a^2-x^2}$ or $a^2-x^2$}%
\label{sub:integrands_involving_a^2-x^2_or_a_2_x_2_}

For the inverse substitution, we use $x=a\sin\theta$ instead of the equivalent $\theta=\sin^{-1}\frac{x}{a}$.
Thus we have:
\[
	a^2-x^2=a^2-a^2\sin^2\theta=a^2(1-\sin^2\theta)=a^2\cos^2\theta
,\]
and:
\[
\frac{\upd x}{\upd \theta}=a\cos\theta
.\]
\begin{exmp}
	Evaluate $\displaystyle{\int \frac{1}{x^2\sqrt{4-x}}\ud x}$.
	\begin{sol}
		Let $x=2\sin\theta$.
		We have $\displaystyle{\frac{\upd x}{\upd\theta}=2\cos\theta}$ and:
		\[
		4-x^2=4\cos^2\theta
		.\]
		Thus we have:
		\begin{align*}
			\int \frac{1}{x^2\sqrt{4-x^2}}\ud x & = \int \frac{1}{4\sin^2\theta(2\cos\theta)}(2\cos\theta)\ud\theta\\
							    & = \frac{1}{4}\int \frac{1}{\sin^2\theta}\ud\theta\\
							    & = \frac{1}{4}\int \csc^2\theta\ud\theta\\
							    & = -\frac{1}{4}\cot\theta+C.
		\end{align*}
		Now, using the identity:
		\[
		1+\cot^2\theta = \csc^2\theta
		,\]
		we have:
		\[
			\cot^2\theta = \csc^2\theta-1 = \left(\frac{2}{x}\right)^2-1 = \frac{4-x^2}{x^2}
		.\]
		Thus, we have:
		\[
			\int \frac{1}{x^2\sqrt{4-x^2}}\ud x = -\frac{\sqrt{4-x^2}}{4x}+C
		.\]
	\end{sol}
\end{exmp}

\subsection{Integrands Involving $\sqrt{x^2-a^2}$ or $x^2-a^2$}%
\label{sub:integrands_involving_x^2-a^2_or_x_2_a_2_}

For the inverse substitution we use $x-a\sec\theta$ instead of the equivalent $\theta =\sec^{-1}\frac{x}{a}$.
Thus we have:
\[
	x^2-a^2=a^2\sec^2\theta-a^2=a^2(\sec^2\theta-1)=a^2\tan^2\theta
,\]
and:
\[
\frac{\upd x}{\upd\theta}=a\sec\theta\tan\theta
.\]
\begin{exmp}
	Find $\displaystyle{\frac{\sqrt{x^2-a^2}}{x}\ud x}$.
	\begin{sol}
		Let $x=a\sec\theta$.
		We have $\displaystyle{\frac{\upd x}{\upd\theta}=a\sec\theta\tan\theta}$ and:
		\[
			\sqrt{x^2-a^2}=a\tan\theta
		.\]
		Thus we have:
		\begin{align*}
			\int \frac{\sqrt{x^2-a^2}}{x}\ud x & = \int \frac{a\tan\theta}{a\sec\theta}a\sec\theta\tan\theta\ud\theta\\
							   & = \int a\tan^2\theta\ud\theta\\
							   & = a\int(\sec^2\theta)-1\ud\theta\\
							   & = a(\tan\theta-\theta)+C\\
							   & = \sqrt{x^2-a^2}-a\sec^{-1}\left\lvert\frac{x}{a}\right\rvert+C.
		\end{align*}
	\end{sol}
\end{exmp}
