Solving second order ODE oscillator I'm currently just taking my first ODE course and one of the questions is,
A projectile of mass $m$ is fired from the origin at speed $v_0$ and angle $\theta$. It is attached to the origin by a spring with spring constant
$k$ and relaxed length zero. Find $x(t)$ and $y(t)$.
Here's how I went about it:
$X$ direction:
$$m \ddot x = -kx$$
$$\ddot x = -\omega^2x$$
$$\omega = \sqrt{\frac{k}{m}}$$

$$x(t) = \frac{v_0}{w}\sin(\omega t)$$
$Y$-direction:
$$m \ddot y = -ky -mg$$
$$\ddot y = -\omega^2y - g$$
$$\dot v + \omega^2y = g$$
Then the integrating factor $=e^{w^2t}$
$$e^{w^2t}v = \int_{0}^{t} -ge^{w^2t}$$
$$v= -\frac{g}{w^2}$$
$$\dot y = -\frac{g}{w^2}$$
$$ y = -\frac{g}{w^2}t$$
Is this right way to go about this? Any help would greatly appreciated. Thank you.
 A: The calculation for $x(t)$ beside some constants that popup after integration is good. Let us consider the initial condition $$x(0)=y(0)=0\;\;\;\;\dot{x}(0)=v_0\cos(\theta)\;\;\;\dot{y}(0)=v_0\sin(\theta)$$ so that at the start, the position of the projectile is the origin. 


*

*Evaluating $x(t)$: yes, I said that your derivation is indeed good but I wanted to point out some thing because, as you're following you're fist course in ODE, you will encounter this concepts many times. You have this ODE to solve:
$$\left\{\begin{matrix}m\ddot{x} = -kx\\x(0)=0\\\dot{x}(0)=v_{0x}\end{matrix}\right.$$
As you said this is equivalent to $$\ddot{x} = -\omega^2 x$$ 
$$x(t) = c_1\sin(\omega t)+c_2\cos(\omega t)\tag{1}$$
Equation $(1)$ is the most general solution to the problem. The constant $c_1,c_2$ are to be found with the initial condition, mainly $$x(0) = c_2 = 0\\\dot{x}(0)=\omega c_1=\omega v_0\cos(\theta)$$ So the exact solution to the problem is, as you said $$x(t) = {v_0\over\omega}\cos(\theta)\sin(\omega t) = v_{0x}\sin(\omega t)$$

*Evaluating $y(t)$: in this case we have the following ODE:
$$\left\{\begin{matrix}m\ddot{y} = -ky-mg\\y(0)=0\\\dot{y}(0)=v_{0y}\end{matrix}\right.$$
You have to notice that the extra factor in this ODE, with respect to the other one, is just a constant (after dividing all by the mass) $g$. So you have two paths to take


*

*Solve the homogeneous equation an than the particular to have the solution as something like $$x(t)=x_h(t) + x_p(t)$$

*You can do a change of variables like $u = -\omega^2 y -g$ and solve the equation in $u$ to then come back to $y$.



I advice the second approach which gets you back to an ODE like the fist one that we solved. So let's begin: notice that $$y = \ddot{u} = -\omega^2 \ddot{y}\Rightarrow \ddot{y} = -\frac{1}{\omega^2}\ddot{u}\\u(0) = -\omega^2 y(0)-g = -g \\\dot{u}(0) = -\omega^2 \dot{y}(0) = -\omega^2 v_{0y}$$ Substitute in the ODE and you get 
$$\left\{\begin{matrix}\ddot{u} = -\omega^2 u\\u(0)=-g\\\dot{u}(0)=-\omega^2 v_{0y}\end{matrix}\right.$$ which has solution $$u(t)=c_1\cos(\omega t)+c_2\sin(\omega t)$$ Let us find the constants $$u(0) = c_1 = -g \\\dot{u}(0) = \omega c_2 = -\omega^2 v_{0y}$$
so $$u(t) = -g\cos(\omega t)-\omega v_{0y}\sin(\omega t)$$ From the definition we gave of $u(t)$ we can find the value of $y(t)$ $$y(t) = -\frac{u(t)}{\omega^2}-{g \over \omega^2} = {g\over\omega^2}\cos(\omega t)+{v_{0y}\over\omega}\sin(\omega t)-{g\over\omega^2}\\ = {g\over\omega^2}\left(\cos(\omega t)-1\right)+{v_{0y}\over\omega}\sin(\omega t)$$ 
In the end, the solution we get is the following $$\begin{align}\left\{\begin{matrix} x(t) = {v_0\over\omega}\cos(\theta)\sin(\omega t) \\y(t)={g\over\omega^2}\left(\cos(\omega t)-1\right)+{v_{0}\over\omega}\sin(\theta)\sin(\omega t)\end{matrix}\right.\end{align}$$
A: Your equations are correct, and as you can see, the two axis are independent.
In the $x$ direction, we have an ordinary harmonic oscillator, $x=a_x\cos\omega t+b_x\sin\omega t$. With the given initial conditions, $x=\dfrac{v_{0x}}\omega\sin\omega t$.
In the $y$ direction, we have a slightly modified oscillator
$$\ddot y=-\omega^2y-g$$ and we can simply shift the equilibrium point as follows
$$\ddot{\left(y+\frac g{\omega^2}\right)}=-\omega^2\left(y+\frac g{\omega^2}\right)$$
so that $y=a_y\cos\omega t+b_y\sin\omega t-\dfrac g{\omega^2}$.
More precisely $y=\dfrac g{\omega^2}(\cos\omega t-1)+\dfrac{v_{0y}}\omega\sin\omega t$.
We have two orthognal sinusoids with a phase difference, so that the trajectory is an ellipse centered on $\left(0,-\dfrac g{\omega^2}\right)$. It tangents a line at the origin in direction $\theta$.

A: The dynamics are given by
$$
m\ddot{\vec r} = -k\vec r + \vec w
$$
with 
$$
\vec r = (x,y)\\
\vec w = (0,-m g)
$$
so we have
$$
m\ddot x + k x = 0\\
m\ddot y + k y - mg = 0
$$
solving with the initial conditions
$$
\dot {\vec r} = v_0(\cos\theta, \sin\theta)\\
\vec r_0 = (0,0)
$$
we get
$$
\left\{
\begin{array}{rcl}
 x(t)& = & v_0\sqrt{\frac mk} \cos \theta \sin \left(\sqrt{\frac km}t \right) \\
 y(t)& = & \frac mk g \left(\cos \left(\sqrt{\frac km} t\right)-1\right)+\sqrt{\frac mk}v_0 \sin \left(\sqrt{\frac km} t\right) \sin (\theta ) \\
\end{array}
\right.
$$
which gives the orbit
$$
g^2 m x^2 \sec ^2\theta+v_0^2 (y-x \tan\theta) (2 g m-k x \tan\theta+k y)
$$
Attached the orbit for $m=1, \theta=\pi/4, k = 1, v_0 = 50$

A: $$\ddot y+ω^2y=−g$$ can also be written as 
$$\frac{d^2}{dt^2} (y-y_*)+ω^2(y-y_*)=0$$ where $y_*=-\frac{g}{ω^2}=-\frac{mg}k$. This is an oscillation in the shifted variable $y-y_*$ in the same way as in the $x$ direction. That is, the $y$ coordiate oscillates around the equilibrium level $y_*$.
A: In fact, the equation can be integrated in vector form.
$$\ddot{\vec r}+\omega^2 \vec r=\vec g$$
has the homogeneous solution
$$\vec r=\vec{c_c}\cos\omega t+\vec{c_s}\sin\omega t$$ and the particular solution $$\vec r=\vec g.$$
Now with the initial conditions,
$$\vec r_0=\vec{c_c}+\vec g=\vec 0,
\\\vec v_0=\omega\vec c_s$$ 
we have
$$\vec r=\vec g-\vec{g}\cos\omega t+\vec{v_0}\frac1{\omega}\sin\omega t.$$
This is an ellipse, inscribed in the parallelogram of vertices
$$\vec g\pm\vec g\pm \vec{v_0}\frac1{\omega}.$$
