80 Star 595 Fork 260

编程语言算法集 / Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
apparent_power.py 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
Rohan Anand 提交于 2023-04-18 13:14 . added reference link. (#8667)
import cmath
import math
def apparent_power(
voltage: float, current: float, voltage_angle: float, current_angle: float
) -> complex:
"""
Calculate the apparent power in a single-phase AC circuit.
Reference: https://en.wikipedia.org/wiki/AC_power#Apparent_power
>>> apparent_power(100, 5, 0, 0)
(500+0j)
>>> apparent_power(100, 5, 90, 0)
(3.061616997868383e-14+500j)
>>> apparent_power(100, 5, -45, -60)
(-129.40952255126027-482.9629131445341j)
>>> apparent_power(200, 10, -30, -90)
(-999.9999999999998-1732.0508075688776j)
"""
# Convert angles from degrees to radians
voltage_angle_rad = math.radians(voltage_angle)
current_angle_rad = math.radians(current_angle)
# Convert voltage and current to rectangular form
voltage_rect = cmath.rect(voltage, voltage_angle_rad)
current_rect = cmath.rect(current, current_angle_rad)
# Calculate apparent power
return voltage_rect * current_rect
if __name__ == "__main__":
import doctest
doctest.testmod()
Python
1
https://gitee.com/TheAlgorithms/Python.git
git@gitee.com:TheAlgorithms/Python.git
TheAlgorithms
Python
Python
master

搜索帮助