Why is it correct to assume $f = e^{\lambda x}$ in differential equation?

$$f'' + f = 0$$ There are many ways to solve this differential equation. Here is one of them: $$f''\cos x +f \cos x=0$$ $$f''\cos x \color{red}{ -f' \sin x +f'\sin x}+f \cos x=0$$ $$(f'\cos x)' +(f \sin x)'=0$$ After integration we get: $$f'\cos x +f \sin x=C_1$$ That you can rewrite as: $$\left ( \dfrac {f}{ \cos x}\right)'=\dfrac {C_1}{\cos^2 x}$$ Integrate and you are done. $$ \dfrac {f}{ \cos x}= {C_1}{\tan x}+C_2$$ Finally: $$ {f}(x)= {C_1}{\sin x}+C_2 \cos x$$


A guess at what a solution might be does not have lead to all possible solutions. For example, consider $y'' = 0$. If you guess that $y(x) = e^{\lambda x}$ then $y''(x) = \lambda^2 e^{\lambda x}$, so $y'' = 0$ only when $\lambda = 0$, which means $e^{\lambda x}$ fits the equation only when $\lambda = 0$. That leads us to the constant solution $y(x) = 1$, whose span is constant functions. This completely misses the solutions $y(x) = ax$ for different constants $a$.

Similarly, if you guess a solution to $y'' + 2y' + y = 0$ has the form $y(x) = e^{\lambda x}$ then $y'' + 2y' + y = (\lambda^2 + 2\lambda + 1)e^{\lambda x}$ so to satisfy the ODE is equivalent to $\lambda^2 + 2\lambda + 1 = 0$, and thus $(\lambda + 1)^2 = 0$. Therefore $\lambda = -1$, and we are led to the solution $e^{-x}$. Its constant multiples gives us solutions $ce^{-x}$, but this is missing the solution $xe^{-x}$.

What helps you know you have genuinely found all solutions to a linear differential equation is knowing in advance the dimension of the solution space. (If the differential equation is not linear, then the solution space is not closed under linear combinations so things become much more complicated.) It can be proved that an $n$th order constant coefficient linear ODE has an $n$-dimensional solution space, so as soon as you find $n$ linearly independent solutions, their linear combinations give you all solutions. As I showed above, guessing at formulas for solutions does not have to lead you to a full set of linearly independent solutions.