"""Lab to Code - Why a phone dies in the cold: Arrhenius ionic conductivity and internal resistance.

Model (illustrative parameters): the electrolyte's ionic conductivity follows Arrhenius with Ea = 20 kJ/mol,
so the cell's internal resistance grows as 1 / k when it cools. The phone draws I amps and shuts down when the
cell voltage, V = V_FULL - SPAN * (1 - s) - I * R, falls to V_CUT. Open-circuit voltage is taken as linear.
"""
from math import exp

R, EA, T0 = 8.314, 20e3, 298.15
V_FULL, V_CUT, SPAN = 4.2, 3.2, 0.9      # volts: full charge, phone shutdown, open-circuit span
R25, I = 0.10, 1.5                        # ohm at 25 C, amps drawn by the phone

for t_c in (25, 10, 0, -10, -20):
    k = exp(-EA / R * (1 / (t_c + 273.15) - 1 / T0))      # conductivity relative to 25 C
    r = R25 / k
    usable = min(1.0, max(0.0, (V_FULL - V_CUT - I * r) / SPAN))
    print(f"{t_c:3} C: k = {k:4.2f}, resistance {r:5.2f} ohm, phone dies with {1 - usable:4.0%} left")
