-
-
Notifications
You must be signed in to change notification settings - Fork 47k
added carrier concentrations algorithm #4791
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
poyea
merged 4 commits into
TheAlgorithms:master
from
SidhaantThakker:carrier_concentration
Oct 11, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,75 @@ | ||
# https://en.wikipedia.org/wiki/Charge_carrier_density | ||
# https://www.pveducation.org/pvcdrom/pn-junctions/equilibrium-carrier-concentration | ||
# http://www.ece.utep.edu/courses/ee3329/ee3329/Studyguide/ToC/Fundamentals/Carriers/concentrations.html | ||
|
||
from __future__ import annotations | ||
|
||
|
||
def carrier_concentration( | ||
electron_conc: float, | ||
hole_conc: float, | ||
intrinsic_conc: float, | ||
) -> tuple: | ||
""" | ||
This function can calculate any one of the three - | ||
1. Electron Concentration | ||
2, Hole Concentration | ||
3. Intrinsic Concentration | ||
given the other two. | ||
Examples - | ||
>>> carrier_concentration(electron_conc=25, hole_conc=100, intrinsic_conc=0) | ||
('intrinsic_conc', 50.0) | ||
>>> carrier_concentration(electron_conc=0, hole_conc=1600, intrinsic_conc=200) | ||
('electron_conc', 25.0) | ||
>>> carrier_concentration(electron_conc=1000, hole_conc=0, intrinsic_conc=1200) | ||
('hole_conc', 1440.0) | ||
>>> carrier_concentration(electron_conc=1000, hole_conc=400, intrinsic_conc=1200) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 37, in <module> | ||
ValueError: You cannot supply more or less than 2 values | ||
>>> carrier_concentration(electron_conc=-1000, hole_conc=0, intrinsic_conc=1200) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 40, in <module> | ||
ValueError: Electron concentration cannot be negative in a semiconductor | ||
>>> carrier_concentration(electron_conc=0, hole_conc=-400, intrinsic_conc=1200) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 44, in <module> | ||
ValueError: Hole concentration cannot be negative in a semiconductor | ||
>>> carrier_concentration(electron_conc=0, hole_conc=400, intrinsic_conc=-1200) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 48, in <module> | ||
ValueError: Intrinsic concentration cannot be negative in a semiconductor | ||
""" | ||
if (electron_conc, hole_conc, intrinsic_conc).count(0) != 1: | ||
raise ValueError("You cannot supply more or less than 2 values") | ||
elif electron_conc < 0: | ||
raise ValueError("Electron concentration cannot be negative in a semiconductor") | ||
elif hole_conc < 0: | ||
raise ValueError("Hole concentration cannot be negative in a semiconductor") | ||
elif intrinsic_conc < 0: | ||
raise ValueError( | ||
"Intrinsic concentration cannot be negative in a semiconductor" | ||
) | ||
elif electron_conc == 0: | ||
return ( | ||
"electron_conc", | ||
intrinsic_conc ** 2 / hole_conc, | ||
) | ||
elif hole_conc == 0: | ||
return ( | ||
"hole_conc", | ||
intrinsic_conc ** 2 / electron_conc, | ||
) | ||
elif intrinsic_conc == 0: | ||
return ( | ||
"intrinsic_conc", | ||
(electron_conc * hole_conc) ** 0.5, | ||
) | ||
else: | ||
return (-1, -1) | ||
|
||
|
||
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.