-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Create apparent_power.py #8664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Create apparent_power.py #8664
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6cac767
Create apparent_power.py
rohan472000 2c1db36
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b588735
Update apparent_power.py
rohan472000 92e1b90
Update apparent_power.py
rohan472000 7f0ca0d
Update apparent_power.py
rohan472000 ecc1c4f
Update electronics/apparent_power.py
rohan472000 811a2db
Update electronics/apparent_power.py
rohan472000 5703541
Update apparent_power.py
rohan472000 9430cdb
Update electronics/apparent_power.py
rohan472000 1d987eb
Update apparent_power.py
rohan472000 0289737
Update apparent_power.py
rohan472000 34eab65
Update apparent_power.py
rohan472000 aad09f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8063be2
Update apparent_power.py
rohan472000 7d5891e
Update apparent_power.py
rohan472000 93c1bb9
Update apparent_power.py
rohan472000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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. | ||
|
||
>>> 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.40952255126032-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 | ||
apparent_power = voltage_rect * current_rect | ||
|
||
return apparent_power | ||
|
||
# Doctests | ||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.