How to compute voltage divider resistors by ratio in Python using UliEngineering

You can easily compute the top resistor of a voltage divider given the bottom resistor value and the division ratio using the UliEngineering Python library:

top_resistor_by_ratio.py
from UliEngineering.Electronics.VoltageDivider import *
from UliEngineering.EngineerIO import *

# Compute top resistor for 1:2 voltage divider with 10k bottom resistor
rtop = top_resistor_by_ratio("10k", 0.5)
print(f"Top resistor (ratio 0.5, bottom 10k): {format_value(rtop, 'Ω')}")

# Compute top resistor for 1:10 voltage divider with 1k bottom resistor
rtop = top_resistor_by_ratio("1k", 0.1)
print(f"Top resistor (ratio 0.1, bottom 1k): {format_value(rtop, 'Ω')}")

Example output

top_resistor_by_ratio_output.txt
Top resistor (ratio 0.5, bottom 10k): 10.0 kΩ
Top resistor (ratio 0.1, bottom 1k): 9.00 kΩ

The top resistor is computed using the formula: $R_{top} = R_{bottom} \times (\frac{1}{ratio} - 1)$, where the ratio is $V_{out}/V_{in}$.


Check out similar posts by category: Electronics, Python