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)
(
voltage: float, current: float, voltage_angle: float, current_angle: float
)
| 3 | |
| 4 | |
| 5 | def apparent_power( |
| 6 | voltage: float, current: float, voltage_angle: float, current_angle: float |
| 7 | ) -> complex: |
| 8 | """ |
| 9 | Calculate the apparent power in a single-phase AC circuit. |
| 10 | |
| 11 | Reference: https://en.wikipedia.org/wiki/AC_power#Apparent_power |
| 12 | |
| 13 | >>> apparent_power(100, 5, 0, 0) |
| 14 | (500+0j) |
| 15 | >>> apparent_power(100, 5, 90, 0) |
| 16 | (3.061616997868383e-14+500j) |
| 17 | >>> apparent_power(100, 5, -45, -60) |
| 18 | (-129.40952255126027-482.9629131445341j) |
| 19 | >>> apparent_power(200, 10, -30, -90) |
| 20 | (-999.9999999999998-1732.0508075688776j) |
| 21 | """ |
| 22 | # Convert angles from degrees to radians |
| 23 | voltage_angle_rad = math.radians(voltage_angle) |
| 24 | current_angle_rad = math.radians(current_angle) |
| 25 | |
| 26 | # Convert voltage and current to rectangular form |
| 27 | voltage_rect = cmath.rect(voltage, voltage_angle_rad) |
| 28 | current_rect = cmath.rect(current, current_angle_rad) |
| 29 | |
| 30 | # Calculate apparent power |
| 31 | return voltage_rect * current_rect |
| 32 | |
| 33 | |
| 34 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected