Finding $x(t)$ for the mechanical system $x'' = -x$ Using energy conservation theorem and method of integration by quadrature, find $x(t)$ for the mechanical system $x'' = -x$, considering a spring with mass $1$ and elasticity constant $1$.
My attempt:
$E = \frac12 \dot{x}^{2} + U(x) = k$, then $\dot{x} = \sqrt{2(E-U(x)}$
Suppose we know $\displaystyle g(x) = \int \frac{1}{\sqrt{2(E-U(x)}} dx$, then, by chain rule:
$\displaystyle\frac{d}{dt} g(x(t)) =  \frac{1}{\sqrt{2(E-U(x)}} \frac{dx}{dt}=1$
Then $g(x(t)) = t+c$
Is this correct?
Thanks
EDIT
I know how to solve this differential equation, I want to know specifically how to solve it with energy conservation and quadrature, because this is an exercise of my Mathematica-Physics/Classical Mechanics course.
 A: The potential energy of the spring is $\frac{1}{2}x^2$ so,
$$\frac{1}{2}x^2+\frac{1}{2} \left(\frac{dx}{dt} \right)^2=E$$
It follows,
$$(\frac{dx}{dt})^2=2E-x^2$$
Supposing that $\frac{dx}{dt} \geq 0$ (ie spring is moving in positive direction), we get:
$$\frac{dx}{dt}=\sqrt{2E-x^2}$$
$$dt=\frac{dx}{\sqrt{2E-x^2}}$$
$$t+c=\arcsin(\frac{x}{\sqrt{2E}})$$
A: $$x(t) = A \cos (2 \pi \omega t + \phi)$$
where $\omega = 1$.
A: you could say
$x'' = kx\\
x = C_1 e^{(\sqrt k)t} + C_2 e^{-(\sqrt k)t}$
$k = -1\\
\sqrt k = i\\
x = C_1 e^{it} + C_2 e^{-it}\\
e^{it} = \cos t+ i\sin t\\
x = A\cos t + B\sin t$
Or you could say 
let $v = x', v'  =x'' = -x$
Giving us the system
$v' = -x\\
x' = v$
or
$\begin{bmatrix} x\\v \end{bmatrix}' = \begin{bmatrix} 0&1\\-1&0\end{bmatrix}\begin {bmatrix} x\\v \end{bmatrix}$
$\mathbf x' = A\mathbf x\\
\mathbf x = e^{At}\mathbf x_0$
and $e^{At} = \sum_{n=0}^{\infty} \frac {(At)^n}{n!}$
$A^2 = -I\\
A^3 = -A\\
A^4 = I$
$e^{At}=\sum_{n=0}^{\infty} \frac {(-1)^n(It)^{2n}}{(2n)!} + \sum_{n=0}^{\infty} \frac {(-1)^n(At)^{2n+1}}{(2n+1)!} = \begin{bmatrix} \cos t&\sin t\\-\sin t&\cos t\end{bmatrix}$
$\begin{bmatrix} x\\v \end{bmatrix} = \begin{bmatrix} x_0\cos t + v_0\sin t\\-x_0 \sin t + v_0\cos t \end{bmatrix}$
finally
$v = \frac{dx}{dt}\\
x'' = \frac {dv}{dt}$
By the chain rule:
$\frac{dv}{dt} = \frac{dv}{dx}\frac{dx}{dt} = \frac{dv}{dx} v$
$\frac{dv}{dx} v = -x$
This is a seprerable diff eq
$\frac 12 v^2 = -\frac12 x^2 + C\\
v = \sqrt {C-x^2}\\
x' =\sqrt {C-x^2}$
Which is also a separable diff eq
$\int \frac {1}{\sqrt{C-x^2}} \ dx = \int dt$
$\arcsin{\frac{x}{\sqrt C}} = t + \phi\\
x = \sqrt C \sin (t+\phi)$ 
A: HINT
Suppose $x(t) = e^{kt}$, where $k\in\mathbb{C}$:
\begin{align*}
x^{\prime\prime} + x = 0 \Longleftrightarrow k^{2}e^{kt} + e^{kt} = 0 \Longleftrightarrow k^{2} + 1 = 0 \Longleftrightarrow k = \pm i
\end{align*}
Therefore $x(t) = Ae^{it} + Be^{-it}$. Can you proceed from here?
