Solution of $y''(x)+y(x)=0$, why is it $y=A\cos(x)+B\sin(x)$? We want to solve $y''(x)+y(x)=0$. We are looking for solutions of the form $y(x)=e^{\lambda x}$. Then, we get $$(\lambda ^2+1)e^{\lambda x}\iff \lambda ^2+1=0\iff \lambda =\pm i.$$
Therefore, the general solution is given by $$y(x)=Ae^{ix}+Be^{-ix}.$$
But why in my solution they say that it's of the form $$y(x)=C\cos(x)+D\sin(x) \ \ ?$$
How can I pass from $Ae^{ix}+Be^{-ix}$ to $C\cos(x)+D\sin(x)$ ? I know that $\cos(x)=\frac{e^{ix}+e^{-ix}}{2}$ and $\sin(x)=\frac{e^{ix}-e^{-x}}{2i}$. Therefore, I can replace these value in $C\cos(x)+D\sin(x)$ and find $A$ and $B$ s.t. it's equal to $Ae^{ix}+Be^{-ix}$. 
But I'm really asking : how do I know that $Ae^{ix}+Be^{-ix}$ can be written in the form of $C\cos(x)+D\sin(x)$ ? Because at my exam I had 0 point on $5$ because I wrote the solution as $Ae^{ix}+Be^{-ix}$, but it's correct, no ?
 A: Recall that $e^{ix}=\cos x +i\sin x$ and $e^{-ix}=\cos x-i\sin x$. Then
$$\cos x=\frac{e^{ix}+e^{-ix}}{2}\qquad\text{and}\qquad \sin x=\frac{e^{ix}-e^{-ix}}{2i}.$$
A: If you are searching for all real-valued solutions to this equation, all you need is to find two linearly independent real-valued solutions (because the space of solutions form a vector space over $\mathbb R$).
As it turns out, a direct way to find these solutions is to momentarily consider complex-valued functions. If you solve for complex functions, as you did, now your only task is to select 2 real-valued functions among those complex solutions (if any). In this case, they happen to be $\cos(x), \sin(x)$, and they suffice to describe all real-valued solutions.
If you do not want to work over the complex valued-functions (which I would not see why), you can assume, for instance, that the solutions will have a Taylor expansion around 0. This is, you look for solutions of the form
$$f(x)= \sum_{i=0}^\infty a_i x^i.$$
When you plug this to the equation, you end up with a recurrence relation on the $a_i$'s. Solving this recurrence relation will give the Taylor representations of the functions you are looking, without seeing directly those complex valued functions.
A: Your solution is also correct. You really just need to substitute in the following manner:
$$Ae^{ix}+Be^{-ix} = \frac{A+B}{2}(e^{ix}+e^{-ix})+\frac{A-B}{2}(e^{ix}-e^{-ix}) = (A+B) \cos x + i(A-B)\sin x$$
Now this is equivalent to $C \cos x + D \sin x,$ since given $A,B$ we can find unique $C,D$ and vice versa.  (This is due to the fact that $\begin{pmatrix}
1 & 1\\ 
i & -i
\end{pmatrix}$ is invertible.)
