<s>[INST] Second order ODE with piecewise term I have the differential equation $\frac{d^2 n}{d z^2} + 2 \frac{dn}{dz} + f(n) = 0$, where $f(n) = \begin{cases} n, \quad 0 \leq n \leq \frac{1}{2} \\ 1 - n, \quad \frac{1}{2} \leq n \leq 1 \end{cases}$. 
I am confused about how to handle the $f(n)$ term. I believe it should be solved in cases, say $0 \leq n \leq \frac{1}{2}$ and $\frac{1}{2} \leq n \leq 1$, like this:
If $0 \leq n \leq \frac{1}{2}$, then $\frac{d^2 n}{d z^2} + 2 \frac{dn}{dz} + n = 0$, which has solution $n(z) = c_1 e^{-z} + c_2 z e^{-z}$. 
If $\frac{1}{2} \leq n \leq 1$, then $\frac{d^2 n}{d z^2} + 2 \frac{dn}{dz} + 1-n = 0$ which has solution $n(z) = c_3e^{(-1+\sqrt{2})z} + c_4 e^{(-1 - \sqrt{2})z} + 1$. 
Would I write the final answer as $$n(z) =
  \begin{cases}
  C_1e^{-z} + C_2 z e^{-z}, \quad & 0 \leq n \leq \frac{1}{2} \\
  C_3e^{(-1+\sqrt{2})z} + C_4 e^{(-1 - \sqrt{2})z} + 1, & \frac{1}{2} \leq n \leq 1
  \end{cases}?
  $$
I am uncomfortable with this because the answer seems "circular" to me because the name of the solution is $n$ but the conditions are on $n$ and not $z$. 
 [/INST] Hint:
Let $u=\dfrac{dn}{dz}$ ,
Then $\dfrac{d^2n}{dz^2}=\dfrac{du}{dz}=\dfrac{du}{dn}\dfrac{dn}{dz}=u\dfrac{du}{dn}$
$\therefore\begin{cases}u\dfrac{du}{dn}+2u+n=0,\quad0\leq n\leq\dfrac{1}{2}\\u\dfrac{du}{dn}+2u+1-n=0,\quad\dfrac{1}{2}\leq n\leq1\end{cases}$
$\begin{cases}\dfrac{du}{dn}=-2-\dfrac{n}{u},\quad0\leq n\leq\dfrac{1}{2}\\\dfrac{du}{dn}=\dfrac{n-1}{u}-2,\quad\dfrac{1}{2}\leq n\leq1\end{cases}$
$\begin{cases}\dfrac{n}{u+n}+\ln(u+n)=c_1,\quad0\leq n\leq\dfrac{1}{2}\\(2-\sqrt2)\ln((\sqrt2-1)(n-1)-u)+(2+\sqrt2)\ln((\sqrt2+1)(n-1)+u)=c_2,\quad\dfrac{1}{2}\leq n\leq1\end{cases}$
</s>