-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Add Ideal Gas Law for physics #6503
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
00cbeb8
add physics ideal gas law
kavienanj 049ef98
run pre commit
kavienanj 63b2f12
Update physics/ideal_gas_law.py
kavienanj 6b9a10d
Update physics/ideal_gas_law.py
kavienanj 3bff0df
run pre commit
kavienanj c56aa57
Update volume return line sugesstion
kavienanj e59078c
Add suggestions
kavienanj 2bb3442
Apply suggestions from code review
cclauss 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,59 @@ | ||
""" | ||
The ideal gas law, also called the general gas equation, is the | ||
equation of state of a hypothetical ideal gas. It is a good approximation | ||
of the behavior of many gases under many conditions, although it has | ||
several limitations. It was first stated by Benoît Paul Émile Clapeyron | ||
in 1834 as a combination of the empirical Boyle's law, Charles's law, | ||
Avogadro's law, and Gay-Lussac's law.[1] The ideal gas law is often written | ||
in an empirical form: | ||
------------ | ||
| PV = nRT | | ||
------------ | ||
P = Pressure (Pa) | ||
V = Volume (m^3) | ||
n = Amount of substance (mol) | ||
R = Universal gas constant | ||
T = Absolute temperature (Kelvin) | ||
|
||
(Description adapted from https://en.wikipedia.org/wiki/Ideal_gas_law ) | ||
""" | ||
|
||
UNIVERSAL_GAS_CONSTANT = 8.314462 # Unit - J mol-1 K-1 | ||
|
||
|
||
def pressure_of_gas_system(moles: float, kelvin: float, volume: float) -> float: | ||
""" | ||
>>> pressure_of_gas_system(2, 100, 5) | ||
332.57848 | ||
>>> pressure_of_gas_system(0.5, 273, 0.004) | ||
283731.01575 | ||
>>> pressure_of_gas_system(3, -0.46, 23.5) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Invalid inputs. Enter positive value. | ||
""" | ||
if moles < 0 or kelvin < 0 or volume < 0: | ||
raise ValueError("Invalid inputs. Enter positive value.") | ||
return moles * kelvin * UNIVERSAL_GAS_CONSTANT / volume | ||
|
||
|
||
kavienanj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def volume_of_gas_system(moles: float, kelvin: float, pressure: float) -> float: | ||
""" | ||
>>> volume_of_gas_system(2, 100, 5) | ||
332.57848 | ||
>>> volume_of_gas_system(0.5, 273, 0.004) | ||
283731.01575 | ||
kavienanj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
>>> volume_of_gas_system(3, -0.46, 23.5) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Invalid inputs. Enter positive value. | ||
""" | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if moles < 0 or kelvin < 0 or pressure < 0: | ||
raise ValueError("Invalid inputs. Enter positive value.") | ||
return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure | ||
|
||
|
||
if __name__ == "__main__": | ||
from doctest import testmod | ||
|
||
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.