I struggle solving the following.
$f''+9f=\cot(3x)$
Homogeneous:
With the Ansatz $f=e^{\lambda x}$ we find
$$P(\lambda)=\lambda^2+9=0 \quad \Rightarrow \quad \lambda_{1,2}=\pm3i$$
so we get
$$y_h(x)=A\cos(3x)+B\sin(3x)$$
Particular:
We use variation of constants and we consider $A,B$ as two functions of x: $A(x), B(x)$. With the Basis $\{\cos(3x), \sin(3x)\}$ we find:
$$\begin{pmatrix}\cos(3x)& \sin(3x) \\ -3\sin(3x) & 3\cos(3x)\end{pmatrix}\cdot\begin{pmatrix}A'(x)\\B'(x)\end{pmatrix}=\begin{pmatrix}0\\ \frac{\cos(3x)}{\sin(3x)}\end{pmatrix}$$
We solve it and get
$$A'(x)=-\frac{1}{3}\cos(3x), \quad B'(X)=\frac{\cos^2(x)}{\sin(3x)}$$
We integrate it:
$$A(x)=\int A'(x) dx = \frac{1}{3}\sin(3x)$$
$B(x)=\int B'(x) dx = \frac{1}{3}\int\frac{\cos^2(3x)}{\sin(3x)}dx=\frac{1}{3}\int\frac{1-\sin^2(3x)}{\sin(3x)}=\frac{1}{3}\int\frac{1}{\sin(3x)}dx-\frac{1}{3}\int \sin(3x)dx$
Now I have problems solving $\int\frac{1}{\sin(3x)}dx$
Any hints? :)
\begin{equation} I = \int \frac{1}{\sin\left(3x\right)}\:dx \end{equation}
Let $u = 3x$ to yield:
\begin{equation} I = \int \frac{1}{\sin\left(3x\right)}dx = \int \frac{1}{\sin\left(u\right)}\cdot\frac{1}{3}\:du = \frac{1}{3}\int \operatorname{cosec}(u) \:du \end{equation}
There are a variety of ways to approach this integral. One method is covered here. You will observe that method requires knowledge of a trigonometric derivative identity. Here I will employ a method that can be used to solve integrals of rational expressions of trigonometric functions. This method is known as the Half Tangent (aka Weierstrass) Substitution. Thus we let $t = \tan\left(\frac{u}{2} \right)$ to yield:
\begin{align} I &= \frac{1}{3}\int \operatorname{cosec}(u) \:du = \frac{1}{3}\int \frac{1}{\sin(u)}\:du \\ &= \frac{1}{3}\int \frac{1}{\frac{2t}{1 + t^2}}\frac{2}{1 + t^2}\:dt = \frac{1}{3} \int \frac{1}{t}\:dt = \frac{1}{3}\ln\left|t \right| + C \\ &= \frac{1}{3}\ln\left|\:\tan\left(\frac{u}{2}\right)\: \right| + C = \frac{1}{3}\ln\left|\:\tan\left(\frac{3x}{2}\right) \: \right| + C \end{align}
Where $C$ is the constant of integration.