Does amplitude really go to infinity in resonance? I was recapping the forced oscillations, and something troubled me. The equation concerning forced oscillation is:
$$
x=\frac{F_0}{m(\omega_0^2-\omega^2)}\cos(\omega t)
$$
I don't understand why this equation predicts that the amplitude will approach infinity as $\omega$ approaches $\omega_0$. One can come up with the argument that in the actual world, there are damping forces, friction etc. The trouble is, however, even in the ideal world, the amplitude wouldn't approach infinity as the spring's restoring force will catch the driving force at some point, and the system will stay in equilibrium.
What I'm wondering is

*

*Is my suggestion in the last paragraph correct?

*If it is correct, what assumption led us to the erroneous model of $x$?

*If it is not correct, what am I missing?

 A: When the frequency of the external force is equal to the natural frequency of the spring, you have resonance, and in idealized conditions, the amplitude increases periodically without bound.
This is because the external force will never be opposite in direction than the spring force. Remember the external force also oscillates. It works together with the spring to keep pushing the amplitude.
Your equation is a steady-state one. It is only valid after an infinite amount of time has passed. When the experiment begins, it will not be valid.
In real, non-ideal scenarios, it can be valid after finite amounts of time, however.
Edit: Considered Puk's comment
A: The thing that you are missing is the "amplitude equals $\infty$" is about the long-term behavior of the system.
What happens when $\omega = \omega_0$ is that the amplitude keeps increasing with time. Yes, the restoring force always brings it back around, but on the next swing, it goes out further than it did last time, in an unbounded manner.
A: $x(t)$ does not instantaneously go to infinity; the case $\omega=\omega_0$ needs special care.  I think an answer directly from the math will help. The driven SHM equation of motion is
$$\tag{1}
x''+\omega_0^2x=\cos(\omega t)
$$
Where I have set all other constants to unity. The general solution of (1) is equal to the homogeneous plus any particular solution
$$
x(t)=x_H(t)+x_P(t)
$$
The homogeneous solution is simply
$$
x_H(t)=C\sin(\omega_0 t)+D\cos(\omega_0 t)
$$
Where $C$ and $D$ are determined by the initial conditions. Note that the amplitude of $x_H$ is fixed for all time by the constants $C$ and $D$. To find a particular solution, I will use undetermined coefficients. Starting with the ansatz
$$\tag{2}
x_P(t)\stackrel{?}{=}A\sin(\omega t)+B\cos(\omega t)
$$
We substitute (2) into (1). If we can consistently solve for the constants $A$ and $B$, then we are done. When $\omega\neq \omega_0$, the result is
$$
A=0\\
B=\frac{1}{\omega_0^2-\omega^2}
$$
Which corresponds to the solution in OP. However, when $\omega=\omega_0$, there are no $A$ and $B$ that make (2) a solution of (1). Try it and see! In this case, we must modify the ansatz (2) to read
$$\tag{3}
x_P(t)\stackrel{?}{=}At \sin(\omega_0 t)+B t\cos(\omega_0 t)
$$
This is a standard procedure with undetermined coefficients: when the homogeneous solution has a term that is equal to the RHS of (1). Substitute (3) into (1) and solve for $A$ and $B$, which yields
$$
A=\frac{1}{2\omega_0} \\
B=0\\
\therefore x_P(t)=\frac{t \sin(\omega_0 t)}{2\omega_0}
$$
Therefore: the particular solution is an oscillating function with amplitude that grows linearly in time. This conclusion follows only from the differential equation (1) with no other physical input or hand-waving.
Edit: With the general solution
$$\tag{4}
x(t)=C\cos(\omega_0 t+\phi) + \frac{F_0}{m}\frac{t}{2\omega_0}\sin(\omega_0 t)
$$
in hand, we may answer your question about the relative phases of the spring and driving force. I've reinstated units and written $x_H$ in a more convenient, equivalent, form. The spring force is
$$
F_{\text{sp}}(t)=-k x(t)
$$
If $C\ll \frac{F_0 t}{\omega_0 m} $ (large times) then the second term on the RHS of (4) is large compared to the first. So we can write approximately
$$
F_{\text{sp}}(t)\approx-\frac{F_0 t}{2}\sin(\omega_0 t) \qquad ;\qquad C\ll \frac{F_0 t}{\omega_0 m}
$$
While the driving force defined in (1) is $F_0 \cos(\omega_0 t)$, compare the $\sin$ to the $\cos$. So for large time, the driving force is approximately $\pi/2$ out of phase with the spring force.
A: I thought it would be helpful to give an intuitive answer about how the amplitude can increase without bound when $\omega = \omega_0$ even though there will always be a point in time where the maximum restoring force of the spring is higher than the maximum value of the periodic driving force.
The point is that it does not matter at all what the restoring force is when the spring is at its maximum extent for a given cycle. At that point, the driving force is close to 0 anyway (assuming a sinusoidal driving force with corresponding period and perfectly aligned phase). The driving force peaks when the mass is moving at its fastest at the middle of its path, and applying a force will always give an acceleration.
In this idealized system, the oscillating spring loses no velocity from one cycle to the next, but then the small force adds a little bit of velocity on each cycle. That means the peak velocity grows without bound, so the amplitude (and hence amplitude of the restoring force) grows without bound as well.
Note that, even in the idealized system, applying the periodic force gets harder and harder. When you push someone in a swing, the faster they are moving as they pass through the bottom, the faster you have to push to apply the same amount of force. Since the driving force acts over the whole amplitude of motion, and work = force $\times$ distance, the work done per cycle (and hence the power consumption) also increases without bound.
Others have mentioned that, in real life, there would be damping, but you are specifically disregarding that.
A: transfer  this differential equation
$${\frac {d^{2}}{d{t}^{2}}}x \left( t \right) +{\omega_{{0}}}^{2}x
 \left( t \right) ={\frac {F\cos \left( \omega\,t \right) }{m}}$$
to Laplace domain (with the initial conditions $~x(0)=0~,\dot{x}(0)=0~)$  you obtain
$$x(s)={\frac {Fs}{m \left( {s}^{2}+{\omega}^{2} \right)  \left( {s}^{2}+{
\omega_{{0}}}^{2} \right) }}
$$
and back to time domain (the solution)
$$x(t)=-{\frac {F\cos \left( \omega\,t \right) }{m \left( {\omega}^{2}-{
\omega_{{0}}}^{2} \right) }}+{\frac {F\cos \left( \omega_{{0}}t
 \right) }{m \left( {\omega}^{2}-{\omega_{{0}}}^{2} \right) }}
$$
the limit of x(t) for  $~\omega=\omega_0~$ is: (l'hospital approach)
$$\lim x(t)\bigg|_{\omega\mapsto\omega_0}=\frac{\partial_\omega \left[-F \left( \cos \left( \omega\,t \right) -\cos \left( \omega_{{0}}t
 \right)  \right) 
\right]}{\partial_\omega\left[m \left( {\omega}^{2}-{\omega_{{0}}}^{2} \right)\right]}\bigg|_{\omega\mapsto\omega_0}=\frac 12\,{\frac {F\sin \left( \omega_{{0}}t \right) t}{m\omega_{{0}}}}
$$
thus x(t) for  $~\omega=\omega_0~$  is not infinity

$$\frac{F}{m}\cos(\omega\,t)\overset{\text{Laplace}}{=}{\frac {Fs}{m \left( {s}^{2}+{\omega}^{2} \right) }}$$
A: Your solution
$$x(t)=\frac{F_0}{m(\omega_0^2-\omega^2)}\cos(\omega t) \tag{1}$$
was derived from the differential equation
$$m(\ddot{x}+\omega_0^2x)=F_0\cos(\omega t) \tag{2}$$
So the forced oscillation (1) is indeed a mathematically correct solution of (2).
But for the resonance case ($\omega=\omega_0$) the solution (1)
becomes ill-defined, and you need to solve (2) in a mathematically
more careful way, as done in @Sal's and @Puk's answers.
But equation (2) is actually a mathematical idealization of the
physical situation because it neglects damping.
In reality there will always be a damping term ($\propto\gamma\dot{x}$)
with a small positive $\gamma$.
So instead of (2) you will have the differential equation
$$m(\ddot{x}+\gamma\dot{x}++\omega_0^2x)=F_0\cos(\omega t) \tag{3}$$
You should try to solve this differential equation.
Hint: Use the approach
$$x(t)=A\cos(\omega t)+B\sin(\omega t) \tag{4}$$
and find the amplitudes $A$ and $B$ as functions of $\omega$.
Then you will see that for the resonance case (at $\omega=\omega_0$,
and also in the range $[\omega_0-\gamma, \omega_0+\gamma]$)
the amplitude will be very large, but not infinitely large.
A: An analogy: Suppose you write a book, and the royalties from the book are \$100k the first year. Each year, the royalties are a percentage $p$ of the prior year's royalties. For instance, if $p=0.5$, the second year you get \$50k, the third year \$25k, and so on. You can use the formula for geometric series to get that the total royalties will be $\frac 1 {1-p}$.
If $p=1$, this formula gives you infinity; if your royalties each year are the same as the year before, then there's no limit to how much money you'll get. Now, that's not to say that you will get an infinite amount of money; at any particular point in time, the money you've received is finite. It's just saying that if you try to find $\lim_{n \rightarrow \infty}T_n$, where $n$ is the year and $T_n$ is the total amount of money you receive up to and including the $n$th year, you won't get a finite limit.
Similarly, if $\omega \neq \omega_0$, then we have that $\lim_{t \rightarrow \infty}A_t$ is given by your formula; as we go on, the oscillation will get closer and closer to being sinusoidal with that amplitude. If $\omega = \omega_0$, then there is no finite limit; each cycle will add more and more energy.

The trouble is, however, even in the ideal world, the amplitude wouldn't approach infinity as the spring's restoring force will catch the driving force at some point, and the system will stay in equilibrium.

I'm not clear on what you're saying here. If the frequencies are exactly equal, then the driving force and restoring force will always be in phase with each other. They will never oppose each other.
A: It is instructive to analyze the problem in time domain. When the driving force is $F_0 \cos(\omega_0 t)$ and the mass is initially at rest at its equilibrium position, the solution is
$$x =\frac{F_0}{2\omega_0m}t\sin(\omega_0t) $$
which represents oscillations that grow in amplitude over time.
It isn't necessarily relevant how the magnitude of the restoring force compares to that of the driving force. Even for small amplitudes, in certain parts of the motion, the driving force will inevitably be smaller in magnitude than (or in the same direction as) the restoring force. This is why the mass periodically comes to a stop and starts accelerating toward the equilibrium position.
It can be seen by integrating the driving force along the trajectory that the driving force does net work on the mass each period, causing the amplitude to grow every cycle. Another way to see that the mass will acquire energy over time is by integrating the sum of the driving and restoring forces between times $nT_0$ and $(n+1)T_0$ where $T_0=2\pi/\omega_0$ is the period. This gives the momentum change at the equilibrium position every cycle. Since the driving force is periodic, it causes no momentum change per cycle. However, the restoring force grows in magnitude and its integral is positive each cycle. This can be intuitively understood as follows.
In the period between times $nT_0$ and $(n+1)T_0$, on average, the restoring force is smaller in magnitude for $x>0$ than for $x<0$, because of the growing amplitude. Therefore, there is a non-zero impulse transfer in the positive direction each cycle, causing the speed at $x=0$ to increase every cycle.
A: In the real world, the vibrational amplitude of an underdamped system driven at resonance does get big- up to the point at which the moving parts in the system bang into their limits, and then something breaks, and then the system flies to pieces and tumbles itself into a big pile of junk. There is a youtube video of exactly this process taking place in a washing machine with a brick in it, set to its spin-dry cycle. The unbalanced weight swinging around at greater and greater speed "finds" all the resonances in the system,  excites them, and builds their amplitudes to the point where parts fly off. At the end of the video, there is no more washing machine.
