使用 UliEngineering 在 Python 中计算电阻器功耗
在此示例中,我们将使用我们的科学和工程 Python 库 UliEngineering 计算流过30 mA 恒定电流的1 kΩ 电阻器的功耗。
现在我们可以使用 power_dissipated_in_resistor_by_current() 计算电阻器功耗
resistor_power_example.py
from UliEngineering.EngineerIO import auto_print
from UliEngineering.Electronics.Resistors import *
# 只计算值:
power = power_dissipated_in_resistor_by_current("1 kΩ", "30 mA") # power = 0.9
# 打印值:打印:打印 "900 mW"
auto_print(power_dissipated_in_resistor_by_current, "1 kΩ", "30 mA")由于结果是 900 mW,你可以推断你需要使用功率额定值至少为一瓦的电阻器。
注意你可以向大多数 UliEngineering 函数传递数字(如 0.03)或字符串(如 30 mA 或 0.03 A)。SI 前缀如 k 和 M 会自动解码
如果你知道电阻器两端的电压,可以使用 power_dissipated_in_resistor_by_voltage()。假设电阻器两端有 1V 压降:
resistor_power_voltage_example.py
from UliEngineering.EngineerIO import auto_print
from UliEngineering.Electronics.Resistors import *
# 只计算值:
power = power_dissipated_in_resistor_by_voltage("1 kΩ", "30 mA") # power = 0.001
# 打印值:打印:打印 "1.00 mW"
auto_print(power_dissipated_in_resistor_by_voltage, "1 kΩ", "30 mA")所以在这种情况下功耗极低 - 只有 1.00 mW - 对大多数实际应用无关紧要。
在许多情况下,你也可以向 UliEngineering 函数传递 NumPy 数组:
resistor_power_numpy_example.py
from UliEngineering.EngineerIO import format_value
from UliEngineering.Electronics.Resistors import *
import numpy as np
# 计算值:
resistors = np.asarray([100, 500, 1000]) # 100 Ω, 500 Ω, 1 kΩ
power = power_dissipated_in_resistor_by_voltage(resistors, "30 mA") # power = 0.001
# power = [9.0e-06 1.8e-06 9.0e-07]Check out similar posts by category:
Electronics, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow