|
| 1 | +""" |
| 2 | +The root-mean-square speed is essential in measuring the average speed of particles |
| 3 | +contained in a gas, defined as, |
| 4 | + ----------------- |
| 5 | + | Vrms = √3RT/M | |
| 6 | + ----------------- |
| 7 | +
|
| 8 | +In Kinetic Molecular Theory, gasified particles are in a condition of constant random |
| 9 | +motion; each particle moves at a completely different pace, perpetually clashing and |
| 10 | +changing directions consistently velocity is used to describe the movement of gas |
| 11 | +particles, thereby taking into account both speed and direction. Although the velocity |
| 12 | +of gaseous particles is constantly changing, the distribution of velocities does not |
| 13 | +change. |
| 14 | +We cannot gauge the velocity of every individual particle, thus we frequently reason |
| 15 | +in terms of the particles average behavior. Particles moving in opposite directions |
| 16 | +have velocities of opposite signs. Since gas particles are in random motion, it's |
| 17 | +plausible that there'll be about as several moving in one direction as within the other |
| 18 | +way, which means that the average velocity for a collection of gas particles equals |
| 19 | +zero; as this value is unhelpful, the average of velocities can be determined using an |
| 20 | +alternative method. |
| 21 | +""" |
| 22 | + |
| 23 | + |
| 24 | +UNIVERSAL_GAS_CONSTANT = 8.3144598 |
| 25 | + |
| 26 | + |
| 27 | +def rms_speed_of_molecule(temperature: float, molar_mass: float) -> float: |
| 28 | + """ |
| 29 | + >>> rms_speed_of_molecule(100, 2) |
| 30 | + 35.315279554323226 |
| 31 | + >>> rms_speed_of_molecule(273, 12) |
| 32 | + 23.821458421977443 |
| 33 | + """ |
| 34 | + if temperature < 0: |
| 35 | + raise Exception("Temperature cannot be less than 0 K") |
| 36 | + if molar_mass <= 0: |
| 37 | + raise Exception("Molar mass cannot be less than or equal to 0 kg/mol") |
| 38 | + else: |
| 39 | + return (3 * UNIVERSAL_GAS_CONSTANT * temperature / molar_mass) ** 0.5 |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + import doctest |
| 44 | + |
| 45 | + # run doctest |
| 46 | + doctest.testmod() |
| 47 | + |
| 48 | + # example |
| 49 | + temperature = 300 |
| 50 | + molar_mass = 28 |
| 51 | + vrms = rms_speed_of_molecule(temperature, molar_mass) |
| 52 | + print(f"Vrms of Nitrogen gas at 300 K is {vrms} m/s") |
0 commit comments