TheAlgorithms/Python · error · ValueError

Non-positive frequency implies vs>v or v0>v (in the opposite

Error message

Non-positive frequency implies vs>v or v0>v (in the opposite direction)

What it means

Error "Non-positive frequency implies vs>v or v0>v (in the opposite direction)" thrown in TheAlgorithms/Python.

Source

Thrown at physics/doppler_frequency.py:95

        ...
    ZeroDivisionError: Division by zero implies vs=v and observer in front of the source
    >>> doppler_effect(100, 330, 10, 340)  # source moving faster than the wave
    Traceback (most recent call last):
        ...
    ValueError: Non-positive frequency implies vs>v or v0>v (in the opposite direction)
    >>> doppler_effect(100, 330, -340, 10)  # observer moving faster than the wave
    Traceback (most recent call last):
        ...
    ValueError: Non-positive frequency implies vs>v or v0>v (in the opposite direction)
    """

    if wave_vel == src_vel:
        raise ZeroDivisionError(
            "Division by zero implies vs=v and observer in front of the source"
        )
    doppler_freq = (org_freq * (wave_vel + obs_vel)) / (wave_vel - src_vel)
    if doppler_freq <= 0:
        raise ValueError(
            "Non-positive frequency implies vs>v or v0>v (in the opposite direction)"
        )
    return doppler_freq


if __name__ == "__main__":
    import doctest

    doctest.testmod()

View on GitHub (pinned to f5988cc097)

Solutions

  1. Keep source and observer speeds below the wave speed so the observed frequency stays positive.

When it happens

Trigger: Thrown at physics/doppler_frequency.py:95 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/93f0b196d07be259. Report an issue: GitHub.