# Notes on Differential Equations (2) —— $\frac{dy}{dx}=ay+\cos\omega t$

Here is the part that we get oscillation input, the $\cos\omega t$ part. Or we can think that's a vibration part, or any thing related to circular motion.

$$\frac{dy}{dx}=ay+\cos\omega t$$ when $y=y(0)$ at $t=0$. Look for $y_p(t)=M\cos\omega t+N\sin\omega t$.

The reason that there is a $\sin$ term in the particular is when we take the derivative of $\cos$, it becomes $\sin$. Therefore there will be a $sin$ term. As for the previous one, the derivative of exponential is itself, so only some constant multiples an exponential term in previous form.

### 1. The first form of the particular solution

First, substitute $y_p(t)$ into the original equation and find $M$ and $N$. After taking derivative of the lefthand side, we have

$$-\omega M\sin\omega t+\omega N\cos\omega t=aM\cos\omega t+aN\sin\omega t+cos\omega t$$

Now the coefficients for $cos$ and $sin$ terms should match at both sides, which is

\begin{align}\left\{\begin{aligned} -aM+\omega N&=1\\ -\omega M-aN&=0 \end{aligned}\right.\end{align}

With simple computation, $M$ and $N$ are

\begin{align}\left\{\begin{aligned} M&=\frac{-a}{\omega^2+a^a}\\ N&=\frac{w}{\omega^2+a^a} \end{aligned}\right.\end{align}

### 2. The solution in polar coordinate form

Here we get one form of the particular solution, but it can be simplified further. Given that we're dealing with $cos$ and $sin$, it's natural to think of phase and the polar coordinate form, which can combine the $cos$ and $sin$ into a single $cos$ term.

$$y_p(t)=G\cos(\omega t-\alpha)$$

where $G$ denotes the gain, the magnitude, or the amplitude, $\alpha$ is the phase shift, or the time lag.

To find the $G$ and $\alpha$, we expand the $cos$ term

\begin{align*}y_p(t)&=G\cos(\omega t-\alpha)\\ &=G(\cos\omega t\cos \alpha +\sin\omega t\sin \alpha)\\ &=G\cos \alpha\cos\omega t + G\sin \alpha\sin\omega t \end{align*}

It's easy to see that this is basically the same form as in the previous form of particular solution,

\begin{align}\left\{\begin{aligned} M&=G\cos\alpha\\ N&=G\sin\alpha \end{aligned}\right.\end{align}

Now the trick is simple. Remember that we have $\sin^2+\cos^2=1$, so we square both sides,

\begin{align}\left\{\begin{aligned} M^2&=G^2\cos^2\alpha\\ N^2&=G^2\sin^2\alpha \end{aligned}\right.\end{align}

\begin{align*}M^2+N^2&=G^2(\cos^2\alpha+\sin^2\alpha)\\ &=G^2\\ G&=\sqrt{M^2+N^2} \end{align*}

To find the value of $\alpha$, we can exploit the equations again, by taking the ratio so that $G$ can get cancelled,

\begin{align}\frac{M}{N}&=\frac{G\cos\alpha}{G\sin\alpha}\\ &=\frac{\cos\alpha}{\sin\alpha}\\ &=\tan\alpha \end{align}

### 3. Complex number form of solution

\begin{align*}\frac{dy}{dt}&=ay_c+\cos\omega t+i\sin\omega t\\ &=ay_c+e^{i\omega t} \end{align*}

where the subscript $c$ in $y_c$ stands for complex number. Here we look for

$$y_c(t)=Ye^{i\omega t}$$

After substitution and taking the derivative, we have

\begin{align*}i\omega Ye^{i\omega t}&=aYe^{i\omega t}+e^{i\omega t}\\ i\omega Y&=aY+1\\ (i\omega - a)Y&=1\\ Y&=\frac{1}{i\omega - a} \end{align*}

Rewrite the complex number $i\omega - a$ to the form of $re^{i\alpha}$, we get $r=\sqrt{a^2+\omega^2}$, thus

$$re^{i\alpha}=\sqrt{a^2+\omega^2}e^{i\alpha}$$

Substitute this result back into $Y$,

\begin{align*}Y&=\frac{1}{i\omega - a}\\ &=\frac{1}{\sqrt{a^2+\omega^2}}e^{-i\alpha} \end{align*}

And now we can plug the $Y$ back into the $y_c(t)=Ye^{i\omega t}$

\begin{align*}y_c(t)&=Ye^{i\omega t}\\ &=\frac{1}{\sqrt{a^2+\omega^2}}e^{-i\alpha}e^{i\omega t}\\ &=\frac{1}{\sqrt{a^2+\omega^2}}e^{i(\omega t-\alpha)}\\ \end{align*}

We take the real part of the solution to match the $\cos\omega t$ term, and of course the imaginary part will match the $\sin\omega t$ term. And the real part will be

\begin{align*}y_c(t)&=\frac{1}{\sqrt{a^2+\omega^2}}e^{i(\omega t-\alpha)}\\ &=\frac{1}{\sqrt{a^2+\omega^2}}\cos(\omega t-\alpha)\\ &=G\cos(\omega t - \alpha) \end{align*}