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

يمكنك بسهولة حساب المقاوم العلوي لمقسم جهد معطى قيمة المقاوم السفلي ونسبة التقسيم باستخدام مكتبة Python UliEngineering:

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button.
Ω ⚠
⚠
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, 'Ω')}")

مثال مخرجات

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Ω

يُحسب المقاوم العلوي باستخدام الصيغة: $R_{top} = R_{bottom} \times (\frac{1}{ratio} - 1)$، حيث النسبة هي $V_{out}/V_{in}$.


Check out similar posts by category: الآلات الحاسبة الإلكترونيات Python