-
Notifications
You must be signed in to change notification settings - Fork 25
Add uconvert
and chemistry example
#48
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 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bb89e87
Add chemistry homework example
gaurav-arya abab555
Add attribution
gaurav-arya b93e193
Merge branch 'main' into ag-example
gaurav-arya 72b89d8
Implement `as_units`
gaurav-arya 380de4d
Add some tests for `as_units`
gaurav-arya 7d06b60
Cleanup example and doctest
gaurav-arya 9b67cad
Add curried form for as_units
gaurav-arya 00afd24
Rename as_units -> as_u
gaurav-arya 54cc371
Add string as_u method
gaurav-arya e099b1d
Finish renaming
gaurav-arya 996ff5c
Simplify docs and test string input to as_u
gaurav-arya 9ffa627
Merge branch 'main' into ag-example
MilesCranmer e08b602
Switch from `as_u` to `uconvert`
MilesCranmer 6ac1e78
Remove string method for uconvert
gaurav-arya 5559886
Remove extraneous toml change
gaurav-arya 2680c14
Expand uconvert tests
MilesCranmer 0e5848b
Reformat uconvert
MilesCranmer 44ed9e4
Expand uconvert tests
MilesCranmer 69cd180
Move `using DynamicQuantities` into example
MilesCranmer 4c34768
Change non-unit error to assertion
MilesCranmer 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821" |
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
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,38 @@ | ||
# Toy Examples with Code | ||
|
||
```jldoctest examples | ||
julia> using DynamicQuantities | ||
|
||
``` | ||
|
||
## 1. Solving a Chemistry Homework Problem | ||
|
||
On your chemistry homework, you are faced with the following problem on the photoelectric effect[^1]: | ||
|
||
[^1]: Attribution: [MIT OCW](https://ocw.mit.edu/courses/5-111sc-principles-of-chemical-science-fall-2014/resources/mit5_111f14_lec04soln/) | ||
|
||
> In a photoelectric effect experiment, electrons are ejected from a titanium surface (work function ``\Phi = 4.33\mathrm{eV}``) following irradition with UV light. | ||
> The energy of the incident UV light is ``7.2 \cdot 10^{-19} \mathrm{J}`` per photon. Calculate the wavelength of the ejected electrons, in nanometers. | ||
|
||
Let's solve this problem with `DynamicQuantities.jl`! | ||
```jldoctest examples | ||
julia> using DynamicQuantities.Constants: h, m_e | ||
|
||
julia> Φ = 4.33u"Constants.eV" # work function | ||
6.93742482522e-19 m² kg s⁻² | ||
|
||
julia> E = 7.2e-19u"J" # incident energy | ||
7.2e-19 m² kg s⁻² | ||
|
||
julia> p = sqrt(2 * m_e * (E - Φ)) # momentum of ejected electrons | ||
2.1871890716439906e-25 m kg s⁻¹ | ||
|
||
julia> λ = h / p # wavelength of ejected electrons | ||
3.029491247878056e-9 m | ||
|
||
julia> uconvert(us"nm", λ) # return answer in nanometers | ||
3.0294912478780556 nm | ||
``` | ||
Since units are automatically propagated, we can verify the dimension of our answer and all intermediates. | ||
Also, using `DynamicQuantities.Constants`, we were able to obtain the (dimensionful!) values of all necessary constants without typing them ourselves. | ||
|
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
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
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
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
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.