title calculating the speed of sound description the speed of sound c is the speed that a sound wave travels per unit time ms during propagation the sound wave propagates through an elastic medium sound propagates as longitudinal waves in liquids and gases and as transverse waves in solids this file calculates the speed of sound in a fluid based on its bulk module and density equation for the speed of sound in a fluid cfluid sqrtks p cfluid speed of sound in fluid ks isentropic bulk modulus p density of fluid source https en wikipedia orgwikispeedofsound calculates the speed of sound in a fluid from its density and bulk modulus examples example 1 water 20c bulkmodulus 2 15mpa density998kgm example 2 mercury 20c bulkmodulus 28 5mpa density13600kgm speedofsoundinafluidbulkmodulus2 15e9 density998 1467 7563207952705 speedofsoundinafluidbulkmodulus28 5e9 density13600 1447 614670861731 calculates the speed of sound in a fluid from its density and bulk modulus examples example 1 water 20 c bulk_modulus 2 15mpa density 998kg m³ example 2 mercury 20 c bulk_modulus 28 5mpa density 13600kg m³ speed_of_sound_in_a_fluid bulk_modulus 2 15e9 density 998 1467 7563207952705 speed_of_sound_in_a_fluid bulk_modulus 28 5e9 density 13600 1447 614670861731
def speed_of_sound_in_a_fluid(density: float, bulk_modulus: float) -> float:
    

    if density <= 0:
        raise ValueError("Impossible fluid density")
    if bulk_modulus <= 0:
        raise ValueError("Impossible bulk modulus")

    return (bulk_modulus / density) ** 0.5


if __name__ == "__main__":
    import doctest

    doctest.testmod()