Calculation of the \(n^\text{th}\) derivatives of \(e^{ax}\cos(bx)\) and \(e^{ax}\sin(bx)\)
Problem formulation
Given functions \(g_1(x) = e^{ax}\cos(bx)\) and \(g_2(x) = e^{ax}\sin(bx)\), calculate \(\frac{d^n}{dx^n}g_1(x)\) and \(\frac{d^n}{dx^n}g_2(x)\), \(n = 1, 2, \ldots\).
Complex analysis approach
Let us consider a function \(f(x) = e^{(a+ib)x}\):
\[ \begin{aligned} f(x) &= e^{ax}e^{ibx} = e^{ax}\left(\cos(bx) + i\sin(bx)\right) = \\ &= e^{ax}\cos(bx) + ie^{ax}\sin(bx) = \\ &= g_1(x) + ig_2(x) \Rightarrow \\ \frac{d^n}{dx^n}f(x) &= \frac{d^n}{dx^n}g_1(x) +i\frac{d^n}{dx^n}g_2(x) \Leftrightarrow \\ \\ \frac{d^n}{dx^n}g_1(x) &= \mathfrak{Re}\left(\frac{d^n}{dx^n}f(x)\right), \\ \frac{d^n}{dx^n}g_2(x) &= \mathfrak{Im}\left(\frac{d^n}{dx^n}f(x)\right). \end{aligned} \]
Here, \(\mathfrak{Re}(\cdot)\) and \(\mathfrak{Im}(\cdot)\) are the real and imaginary parts of a complex number.
Then, the \(n^\text{th}\) derivative of \(f(x)\) is given by
\[ \begin{aligned} \frac{d^n}{dx^n}f(x) &= (a+ib)^ne^{(a+ib)x} = \\ &= \left[ \begin{aligned} a+ib &= re^{i\theta}, \text{ where} \\ r &= \sqrt{a^2+b^2} \\ \theta &= \arg(a+ib) \\ &\Downarrow \\ (a+ib)^n &= r^ne^{in\theta} \end{aligned} \right] = \\ \\ &= r^ne^{in\theta}e^{(a+ib)x} = \\ &= r^ne^{ax}\left(\cos(n\theta)+i\sin(n\theta)\right)\left(\cos(bx)+i\sin(bx)\right) = \\ & \begin{aligned}=r^ne^{ax}&\left((\underbrace{\cos(bx)\cos(n\theta)-\sin(bx)\sin(n\theta)}_{\cos(bx+n\theta)})\right. + \\ &+i\left.(\underbrace{\sin(bx)\cos(n\theta)+\cos(bx)\sin(n\theta)}_{\sin(bx+n\theta)})\right)=\end{aligned} \\ &= r^ne^{ax}\cos(bx + n\theta) + ir^ne^{ax}\sin(bx + n\theta) \Rightarrow \\ \\ \frac{d^n}{dx^n}g_1(x) &= \frac{d^n}{dx^n}\left(e^{ax}\cos(bx)\right) = r^ne^{ax}\cos(bx + n\theta), \\ \frac{d^n}{dx^n}g_2(x) &= \frac{d^n}{dx^n}\left(e^{ax}\sin(bx)\right) = r^ne^{ax}\sin(bx + n\theta), \\ \text{where } r &= \sqrt{a^2+b^2},\: \theta = \arg(a+ib). \\ \end{aligned} \]
Linear algebra approach
Let us consider another approach that, from my point of view, is less efficient but is quite interesting.
Let us consider a set of all linear combinations of functions \(g_1(x)\) and \(g_2(x)\):
\[ S = \text{span}\left(g_1(x), g_2(x)\right) = \left\{f(x) = c_1g_1(x) + c_2g_2(x)|c_1, c_2 \in \mathbb{R}\right\}. \] Then, one may consider an operator \(T: S \rightarrow \mathbb{R}^2\) such as
\[ \forall f(x)=c_1g_1(x) + c_2g_2(x) \in S,\: T\left[f(x)\right] = \begin{pmatrix}c_1 \\ c_2\end{pmatrix} \Leftrightarrow T^{-1}\left[\begin{pmatrix}c_1 \\ c_2\end{pmatrix}\right] = c_1g_1(x) + c_2g_2(x) = f(x). \]
Now, let us differentiate a function \(f(x)\in S\):
\[ \begin{aligned} \frac{d}{dx}f(x) &= \frac{d}{dx}\left(c_1g_1(x) + c_2g_2(x)\right) = \\ &= c_1\frac{d}{dx}g_1(x) + c_2\frac{d}{dx}g_2(x) = \\ &= c_1\frac{d}{dx}\left(e^{ax}\cos(bx)\right) + c_2\frac{d}{dx}\left(e^{ax}\sin(bx)\right) = \\ &= c_1\left(ae^{ax}\cos(bx) - be^{ax}\sin(bx)\right) + c_2\left(ae^{ax}\sin(bx) + be^{ax}\cos(bx)\right) = \\ &= \underbrace{(ac_1 + bc_2)}_{\widetilde{c}_1}e^{ax}\cos(bx) + \underbrace{(-bc_1 + ac_2)}_{\widetilde{c}_2}e^{ax}\sin(bx) = \\ &= \widetilde{c}_1e^{ax}\cos(bx) + \widetilde{c}_2e^{ax}\sin(bx) = \\ &= \widetilde{c}_1g_1(x) + \widetilde{c}_2g_2(x) \in S. \end{aligned} \]
The latter means that the differentiation operator \(\frac{d}{dx}\) acts from \(S\) to \(S\), \(\frac{d}{dx}: S\rightarrow S\), and can be represented as
\[ \frac{d}{dx} = T^{-1}DT, \text{ where } D\left[\begin{pmatrix}c_1 \\ c_2\end{pmatrix}\right] = \begin{pmatrix} a & b \\ -b & a\end{pmatrix}\begin{pmatrix}c_1 \\ c_2\end{pmatrix}. \]
Thus, for \(f(x) = c_1g_1(x) + c_2g_2(x) \in S\),
\[ \begin{aligned} \frac{d}{dx}f(x) &= \left(T^{-1}DT\right)[f(x)] = T^{-1}\left[D\left[T\left[f(x)\right]\right]\right] = \\ &= T^{-1}\left[D\left[\begin{pmatrix}c_1 \\ c_2\end{pmatrix}\right]\right] = \\ &= T^{-1}\left[\begin{pmatrix} a & b \\ -b & a\end{pmatrix}\begin{pmatrix} c_1 \\ c_2\end{pmatrix}\right] = \\ &= T^{-1}\left[\begin{pmatrix} ac_1 + bc_2 \\ -bc_1 + ac_2\end{pmatrix}\right] = T^{-1}\left[\begin{pmatrix} \widetilde{c}_1\\ \widetilde{c}_2\end{pmatrix}\right] = \\ &= \widetilde{c}_1g_1(x) + \widetilde{c}_2g_2(x). \end{aligned} \]
Then,
\[ \begin{aligned} \frac{d^n}{dx^n}\left[\cdot\right] &= \underbrace{\frac{d}{dx}\frac{d}{dx}\ldots\frac{d}{dx}\left[\cdot\right]}_{n\text{ times}} = \\ &= \underbrace{(T^{-1}D\overbrace{T)(T^{-1}}^{= I}DT)\ldots (T^{-1}D \overbrace{T)(T^{-1}}^{= I}DT) }_{n\text{ times}} = \left[I \text{ is an identity operator}\right] = \\ &= T^{-1}\underbrace{\left(D\ldots D\right)}_{n\text{ times}}T = \\ &= T^{-1}D^nT, \end{aligned} \]
where operator \(D^n\) is represented by \(\mathbf{D}^n\), the \(n^\text{th}\) power of matrix \(\mathbf{D} = \begin{pmatrix} a & b \\ -b & a \end{pmatrix}\).
Calculating \(\mathbf{D}^n\)
If \(\mathbf{V} = \left(\mathbf{v}_1\: \mathbf{v}_2\right)\) is a matrix of eigenvectors of matrix \(\mathbf{D}\), and \(\mathbf{\Lambda} = \begin{pmatrix}\lambda_1 & 0 \\ 0 & \lambda_2 \end{pmatrix}\) is a matrix of eigenvalues of matrix \(\mathbf{D}\), then
\[ \mathbf{D} = \mathbf{V}\mathbf{\Lambda}\mathbf{V}^{-1}, \text{ and } \mathbf{D}^n = \mathbf{V}\mathbf{\Lambda}^n\mathbf{V}^{-1}. \]
Let us calculate eigenvalues \(\lambda_1\), \(\lambda_2\), and eigenvectors \(\mathbf{v}_1\), \(\mathbf{v}_2\).
\(\lambda_1\), \(\lambda_2\) are solutions of the equation
\[ \det(\mathbf{D}-\lambda\mathbf{I}) = 0 \Leftrightarrow \det\begin{pmatrix}a-\lambda & b \\ -b & a-\lambda\end{pmatrix} = (a-\lambda)^2+b^2=0 \Leftrightarrow \left\{ \begin{aligned} \lambda_1 &= a+ib \\ \lambda_2 &= a-ib \end{aligned} \right. \] Now, let us calculate eigenvectors:
\[ \begin{aligned} \lambda_1 &= a+ib, \: \mathbf{v}_1 = \begin{pmatrix}v_{11} \\ v_{12}\end{pmatrix}, \text{ and }\mathbf{D}\mathbf{v}_1 = \lambda_1\mathbf{v}_1 \Leftrightarrow \\ &\left. \begin{aligned} av_{11} + bv_{12} &= (a+ib)v_{11} \\ -bv_{11} + av_{12} &= (a+ib)v_{12} \end{aligned} \right| \Rightarrow \mathbf{v}_1=\begin{pmatrix}1 \\ i\end{pmatrix}; \\ \\ \lambda_2 &= a-ib, \: \mathbf{v}_2 = \begin{pmatrix}v_{21} \\ v_{22}\end{pmatrix}, \text{ and }\mathbf{D}\mathbf{v}_2 = \lambda_2\mathbf{v}_2 \Leftrightarrow \\ &\left. \begin{aligned} av_{21} + bv_{22} &= (a-ib)v_{21} \\ -bv_{21} + av_{22} &= (a-ib)v_{22} \end{aligned} \right| \Rightarrow \mathbf{v}_2=\begin{pmatrix}i \\ 1\end{pmatrix}. \\ \\ \end{aligned} \] Then,
\[ \mathbf{V} = \begin{pmatrix} 1 & i \\ i & 1\end{pmatrix}, \: \mathbf{\Lambda} = \begin{pmatrix} a+ib & 0 \\ 0 & a-ib\end{pmatrix}, \: \mathbf{V}^{-1} = \begin{pmatrix} 0.5 & -0.5i \\ -0.5i & 0.5\end{pmatrix} \Rightarrow \]
\[ \begin{aligned} \mathbf{D}^n = \mathbf{V}\mathbf{\Lambda}^n\mathbf{V}^{-1} &= \begin{pmatrix} 1 & i \\ i & 1\end{pmatrix} \begin{pmatrix} (a+ib)^n & 0 \\ 0 & (a-ib)^n\end{pmatrix} \begin{pmatrix} 0.5 & -0.5i \\ -0.5i & 0.5\end{pmatrix} = \\ &= \begin{pmatrix} 1 & i \\ i & 1\end{pmatrix} \begin{pmatrix} 0.5(a+ib)^n & -0.5i(a+ib)^n \\ -0.5i(a-ib)^n & 0.5(a-ib)^n\end{pmatrix} = \\ &= \begin{pmatrix} \frac{(a+ib)^n + (a-ib)^n}{2} & \frac{(a+ib)^n-(a-ib)^n}{2i} \\ -\frac{(a+ib)^n - (a-ib)^n}{2i}& \frac{(a+ib)^n+(a-ib)^n}{2} \end{pmatrix} = \\ &=\left[ \begin{aligned} &\text{notice that for }r = \sqrt{a^2+b^2} \text{ and }\theta = \arg(a+ib),\\ &\left.\begin{aligned} (a+ib)^n &= (re^{i\theta})^n = r^ne^{in\theta} \\ (a-ib)^n &= (re^{-i\theta})^n = r^ne^{-in\theta} \end{aligned} \right| \Rightarrow \\ \\ &\frac{(a+ib)^n + (a-ib)^n}{2} = r^n\frac{e^{in\theta}+e^{-in\theta}}{2} = r^n\cos(n\theta) \\ &\frac{(a+ib)^n - (a-ib)^n}{2i} = r^n\frac{e^{in\theta}-e^{-in\theta}}{2i} = r^n\sin(n\theta) \\ \end{aligned} \right] = \\ &= \begin{pmatrix} r^n\cos(n\theta) & r^n\sin(n\theta) \\ -r^n\sin(n\theta) & r^n\cos(n\theta)\end{pmatrix}. \end{aligned} \]
Calculating the \(n^\text{th}\) derivative
Now, we can calculate the derivative of \(f(x) = c_1g_1(x) + c_2g_2(x) \in S\):
\[ \begin{aligned} \frac{d^n}{dx^n}f(x) &= \frac{d^n}{dx^n}\left(c_1g_1(x)+c_2g_2(x)\right) = c_1\frac{d^n}{dx^n}g_1(x) + c_2\frac{d^n}{dx^n}g_2(x) = \\ &= T^{-1}D^nT\left[c_1g_1(x)+c_2g_2(x)\right] = \\ &= T^{-1}\left[ D^n\left[\begin{pmatrix} c_1 \\ c_2 \end{pmatrix}\right]\right] = \\ &= T^{-1}\left[\mathbf{D}^n\begin{pmatrix} c_1 \\ c_2 \end{pmatrix}\right] = \\ &= T^{-1}\left[\begin{pmatrix}r^n\cos(n\theta) & r^n\sin(n\theta) \\ -r^n\sin(n\theta) & r^n\cos(n\theta)\end{pmatrix}\begin{pmatrix} c_1 \\ c_2 \end{pmatrix}\right] = \\ &= T^{-1}\left[\begin{pmatrix}c_1r^n\cos(n\theta) + c_2r^n\sin(n\theta) \\ \\ -c_1r^n\sin(n\theta) + c_2r^n\cos(n\theta)\end{pmatrix}\right] = \\ \\ &= \left(c_1r^n\cos(n\theta) + c_2r^n\sin(n\theta)\right)e^{ax}\cos(bx) + \\ &+ \left(-c_1r^n\sin(n\theta) + c_2r^n\cos(n\theta)\right)e^{ax}\sin(bx) = \\ \\ &= c_1r^ne^{ax}\underbrace{\left(\cos(bx)\cos(n\theta)-\sin(bx)\sin(n\theta)\right)}_{\cos(bx+n\theta)}+ \\ &+ c_2r^ne^{ax}\underbrace{\left(\sin(bx)\cos(n\theta)+\cos(bx)\sin(n\theta)\right)}_{\sin(bx+n\theta)} = \\ &= c_1r^ne^{ax}\cos(bx+n\theta)+c_2r^ne^{ax}\sin(bx+n\theta) \Rightarrow \\ \\ \frac{d^n}{dx^n}g_1(x) &= \frac{d^n}{dx^n}\left(e^{ax}\cos(bx)\right) = r^ne^{ax}\cos(bx+n\theta)\text{ and } \\ \frac{d^n}{dx^n}g_2(x) &= \frac{d^n}{dx^n}\left(e^{ax}\sin(bx)\right) = r^ne^{ax}\sin(bx+n\theta), \\ \end{aligned} \]
which is the same result we obtained with complex analysis approach.