how to solve $\frac{d^2y}{dx^2}=-ky$? I read this question in my math textbook. But even its solution I can't even understand. This is in the introduction to differential equation. So I have't yet learnt any formal way to solve DE.
$$\frac{d^2y}{dx^2}=-ky$$
Step 1 (Multiply each side by $2\frac{dy}{dx}$): 
$$2\frac{d^2y}{dx^2}\frac{dy}{dx}=-2ky\frac{dy}{dx}$$
Step 2 (Integrate both sides) And somehow get:
$$(\frac{dy}{dx})^2=-ky^2+C$$
Step 3 I don't know. Are you supposed to take the square root?
I am confused as how the author get from Step 1 to Step 2. I know for the right hand side, he integrate with respect to $y$. But what happen the left hand side? And how do you solve the rest of it?
 A: $$y'' + ky = 0$$
The characteristic equation reads
$$\lambda^2 + k = 0$$ 
Hence
$$\lambda_{1, 2} = \pm i\sqrt{k}$$
hence the solution follows
$$y(x) = C_1 e^{-i\sqrt{k}x} + C_2 e^{ i \sqrt{k}x}$$
Or if you prefer
$$y(x) = C_1 \cos\sqrt{k}x + C_2 \sin\sqrt{k}x$$
A: From step 2 to step 3 he integrated both sides with respect to $x$, not $y$.  You can check it by differentiating step 3 with respect to $x$.  On the left, you have $(\frac {dy}{dx})^2,$, which differentiates by the chain rule to $2(\frac {dy}{dx})(\frac {dy}{dx})'=2(\frac {dy}{dx})(\frac {d^2y}{dx^2})$ On the right you differentiate $-ky^2+C$ to $-2kyy'$
A: Here is another approach which gives the answer directly. Your approach gives the answer in terms of $x$ as a function of $y$.

The problem is simpler if $k$ is positive. Let $k = a^{2} > 0$ and then we put $t = ax$ so that $$\frac{dy}{dx} = a\frac{dy}{dt},\frac{d^{2}y}{dx^{2}} = a^{2}\frac{d^{2}y}{dt^{2}} = k\frac{d^{2}y}{dt^{2}}$$ so that the equation is transformed into $$\frac{d^{2}y}{dt^{2}} + y = 0\tag{1}$$ Let the initial conditions be $y(0) = A, y'(0) = B$ (here prime denotes derivative with respect to $t$). Then we show that $y = f(t) = A\cos t + B\sin t$ for all real $t$.
To do so first we note that the function $h(t) = f(t) - A\cos t - B\sin t$ also satisfies $h''(t) + h(t) = 0$ and $h(0) = h'(0) = 0$. Consider the function $$F(t) = \{h(t)\}^{2} + \{h'(t)\}^{2}$$ Clearly we have $$F'(t) = 2h'(t)\{h(t) + h''(t)\} = 0$$ and hence $F$ is constant so that $F(t) = F(0) = 0$. Thus we can see that $$\{h(t)\}^{2} + \{h'(t)\}^{2} = 0$$ for all real $t$. Since $h, h'$ are real it follows that $h(t) = 0$ for all real $t$ and hence $f(t) = A\cos t + B\sin t$.
Transforming this to variable $x$ we can see that the solution to the original equation is given by $$y = y(0)\cos \sqrt{k}x + \frac{y'(0)}{\sqrt{k}}\sin\sqrt{k}x$$
