[Physics] Why does the speed of sound decrease at high altitudes although the air density decreases

acousticsairdensityfluid dynamicswaves

I understand that the speed of sound is inversely proportional to the density of the medium as shown here and as answered for this question.

The problem now is that the speed of sound in air actually decreases with altitude although the density of the air decreases. This is shown here and here.

I understand that the speed of sound also depends on the elasticity, but I'm not sure how this can change for air.

So what is actually happening? How can the speed of sound decrease although the density has also decreased?

Best Answer

Wikipedia gives a pretty much straightforward answer. In an ideal gas, the speed of sound depends only on the temperature:

$$ v = \sqrt{\frac{\gamma \cdot k \cdot T}{m}} $$

So it neither decreases, nor increases with altitude, but just follows air temperature as can be seen in this graph:

enter image description here