How to integrate a function of $Ae^{kt} + Be^{-kt}$? How to integrate
$$\int_0^T \frac{C(Ae^{kt} - Be^{-kt}) + D}{(Ae^{kt} + Be^{-kt})^2} dt$$
where A, B, C, D and k are some constants?
I tried using integration by parts where $U = C(Ae^{kt} - Be^{-kt}) + D$ and $dV = (Ae^{kt} + Be^{-kt})^{-2}$.
Using the usual formula for anti-derivate, I got $V = -(Ae^{kt} + Be^{-kt})^{-1}(kAe^{kt} - kBe^{-kt})^{-1}$. However, if I then recompute $dV$ from this $V$, I can't get back to the original $dV = (Ae^{kt} + Be^{-kt})^{-2}$.
What did I do wrong?
Is there another way to derive this integral?
Update
Use substitution: Let $u = (Ae^{kt} + Be^{-kt})^{-1}$. It follows that $du = -\frac{k(Ae^{kt} - Be^{-kt})}{(Ae^{kt} + Be^{-kt})^2}$. But how do I incorporate the constant D?
Solution
See user5713492's answer below.
 A: If we integrate by parts,
$$\begin{align}\int\frac{(Ae^{kt}-Be^{-kt})^2}{(Ae^{kt}+Be^{-kt})^2}dt&=-\frac1{k(Ae^{kt}+Be^{-kt})}(Ae^{kt}-Be^{-kt})+\frac1k\int\frac{k(Ae^{kt}+Be^{-kt})}{(Ae^{kt}+Be^{-kt})}dt\\
&=-\frac{(Ae^{kt}-Be^{-kt})}{k(Ae^{kt}+Be^{-kt})}+t+C_1\end{align}$$
And $(Ae^{kt}+Be^{-kt})^2-(Ae^{kt}-Be^{-kt})^2=4AB$
so we can say
$$\begin{align}I&=\int\frac{C(Ae^{kt}-Be^{-kt})+D}{(Ae^{kt}+Be^{-kt})^2}dt\\
&=\int\frac{C(Ae^{kt}-Be^{-kt})+\frac D{4AB}(Ae^{kt}+Be^{-kt})^2-\frac D{4AB}(Ae^{kt}-Be^{-kt})^2}{(Ae^{kt}+Be^{-kt})^2}dt\\
&=-\frac C{k(Ae^{kt}+Be^{-kt})}+\frac D{4AB}t+\frac D{4AB}\frac{(Ae^{kt}-Be^{-kt})}{k(Ae^{kt}+Be^{-kt})}-\frac D{4AB}t+C_2\\
&=\frac{D(Ae^{kt}-Be^{-kt})-4ABC}{4kAB(Ae^{kt}+Be^{-kt})}+C_2\end{align}$$
A: Hint Since for any constant $\alpha$ we have $$\frac{d}{dt} e^{\alpha t} = \alpha e^{\alpha t},$$ the derivative of the quantity $$A e^{k t} + B e^{-k t}$$ in parentheses in the denominator is a multiple of the quantity $$A e^{k t} - B e^{-k t}$$ in one of the summands of the numerator, suggesting a natural choice of substitution.
A: Alternatively, we can rewrite the integral in terms of hyperbolic functions.
Notice that the quantities in parentheses look like hyperbolic functions, albeit with potentially different coefficients of $e^{kt}, e^{-k t}$. By shifting (and, optionally, scaling) the independent variable $t$, we can produce an expression that can be written easily in terms of such functions.
Suppose $k \neq 0$ and that $A, B$ are both positive (or both negative). In terms of the variable $u$ characterized by $$k t = u - u_0$$ we have
$$A e^{k t} + B e^{-k t} = A e^{u - u_0} + B e^{-(u - u_0)} = A e^{-u_0} e^u + B e^{u_0} e^{-u} .$$ There is a unique $u_0$ such that $$A e^{-u_0} = B e^{u_0} $$ (we can solve for $u_0$ explicitly, but this turns out not to be necessary), and if for this value of $u_0$ we denote $$\lambda := A e^{-u_0} = B e^{u_0} ,$$ then
$$A e^{k t} + B e^{-k t} = \lambda \cosh u \qquad \textrm{and} \qquad A e^{-k t} - B e^{-k t} = \lambda \sinh u .$$
So, we can rewrite the (indefinite) integral as
$$\frac{1}{k} \int \frac{C (\lambda \sinh u) + D}{(\lambda \cosh u)^2} du = \underbrace{\frac{C}{k \lambda} \int \tanh u \operatorname{sech} u \,du}_{(1)} + \underbrace{\frac{D}{k \lambda^2} \int \operatorname{sech}^2 u \,du}_{(2)} ,$$
but both of the integrals on the right-hand side are elementary.
For example, the integral in $(1)$ has value $$-\operatorname{sech} u + K = \frac{1}{\cosh u} + K $$ for an arbitrary constant $K$, so term $(1)$ is
$$\frac{C}{k \lambda} \left( -\frac{1}{\cosh u} + K \right) = -\frac{C}{k} \cdot \frac{1}{\lambda \cosh u} + K' = -\frac{C}{k (A e^{k t} + B e^{-k t})} + K'$$ for an arbitrary constant $K'$.
We can handle term $(2)$ similarly.
We can treat the case that $A$ and $B$ have opposite signs separately, but notice that the antiderivative we produced treating the first case is an antiderivative of the original integrand irrespective of the signs of $A, B$.
