TheAlgorithms/Python · error · ValueError
mobility cannot be negative
Error message
mobility cannot be negative
What it means
Thrown by electric_conductivity() when mobility < 0 while exactly one argument is 0. Carrier mobility mu (m^2/V*s) is non-negative by definition; a negative value would invert the sigma = n*e*mu relation, so it is rejected before the solver branches run.
Source
Thrown at electronics/electric_conductivity.py:52
...
ValueError: mobility cannot be negative
>>> electric_conductivity(conductivity=50, electron_conc=0, mobility=0)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
>>> electric_conductivity(conductivity=50, electron_conc=200, mobility=300)
Traceback (most recent call last):
...
ValueError: You cannot supply more or less than 2 values
"""
if (conductivity, electron_conc, mobility).count(0) != 1:
raise ValueError("You cannot supply more or less than 2 values")
elif conductivity < 0:
raise ValueError("Conductivity cannot be negative")
elif electron_conc < 0:
raise ValueError("Electron concentration cannot be negative")
elif mobility < 0:
raise ValueError("mobility cannot be negative")
elif conductivity == 0:
return (
"conductivity",
mobility * electron_conc * ELECTRON_CHARGE,
)
elif electron_conc == 0:
return (
"electron_conc",
conductivity / (mobility * ELECTRON_CHARGE),
)
else:
return (
"mobility",
conductivity / (electron_conc * ELECTRON_CHARGE),
)
if __name__ == "__main__":View on GitHub (pinned to f5988cc097)
Solutions
- Pass a positive mobility (electrons in Si at room temperature: ~0.135 m^2/V*s).
- If mobility is the unknown, pass 0 for it and supply conductivity and electron_conc.
- Sanity-check material parameter tables once at load time.
Example fix
# before electric_conductivity(conductivity=50, electron_conc=1e21, mobility=-0.135) # after electric_conductivity(conductivity=50, electron_conc=1e21, mobility=0.135)
Defensive patterns
Strategy: validation
Validate before calling
if mobility < 0:
raise ValueError("mobility must be >= 0")
name, value = electric_conductivity(conductivity, electron_conc, mobility) Prevention
- Sanity-check material tables (e.g. mu_e in Si ~ 0.135 m^2/V*s) at load time.
- Use 0 to request solving for mobility, never a negative placeholder.
When it happens
Trigger: electric_conductivity(conductivity=50, electron_conc=0, mobility=-300) — valid zero-count but negative mobility.
Common situations: Typo'd minus signs in hand-entered material parameters; Hall-effect derivations producing signed 'effective' mobilities; unit tables copied with negative conventions.
Related errors
- Electron concentration cannot be negative in a semiconductor
- Hole concentration cannot be negative in a semiconductor
- Intrinsic concentration cannot be negative in a semiconducto
- Conductivity cannot be negative
- Electron concentration cannot be negative
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/e257959db7f2cb68.
Report an issue: GitHub.