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.


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
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}$$