Computing resistor power dissipation in Python using UliEngineering
In this example we’ll calculate the power dissipation of a 1 kΩ resistor with a constant current of 30 mA flowing through it, using our science and engineering Python library UliEngineering.
In order to install UliEngineering (a Python3-only library), run
sudo pip3 install -U UliEngineering
Now we can compute the resistor power dissipation using power_dissipated_in_resistor_by_current()
from UliEngineering.EngineerIO import auto_print
from UliEngineering.Electronics.Resistors import *
# Just compute the value:
power = power_dissipated_in_resistor_by_current("1 kΩ", "30 mA") # power = 0.9
# Print value: prints: prints "900 mW"
auto_print(power_dissipated_in_resistor_by_current, "1 kΩ", "30 mA")
Since the result is 900 mW
, you can deduce that you need to use a resistor with a power rating of at least one Watt.
Note that you can pass both numbers (like 0.03
) or strings (like 30 mA
or 0.03 A
) to most UliEngineering functions. SI prefixes like k
and M
are automatically decoded
If you know the voltage across the resistor, you can use power_dissipated_in_resistor_by_voltage()
. Let’s assume there is 1V
dropped across the resistor:
from UliEngineering.EngineerIO import auto_print
from UliEngineering.Electronics.Resistors import *
# Just compute the value:
power = power_dissipated_in_resistor_by_voltage("1 kΩ", "30 mA") # power = 0.001
# Print value: prints: prints "1.00 mW"
auto_print(power_dissipated_in_resistor_by_voltage, "1 kΩ", "30 mA")
So in this case the power dissipation is extremely low - only 1.00 mW
- and won’t matter for most practical applications.
In many cases, you can also pass NumPy arrays to UliEngineering functions:
from UliEngineering.EngineerIO import format_value
from UliEngineering.Electronics.Resistors import *
import numpy as np
# Compute the value:
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]