Added forward bias voltage#7871
Closed
sadiqebrahim wants to merge 7 commits intoTheAlgorithms:masterfrom
Closed
Conversation
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
Contributor
|
@cclauss I know this is on hold but its a pretty quick and easy one to merge |
for more information, see https://pre-commit.ci
cclauss
reviewed
Oct 30, 2022
Co-authored-by: Christian Clauss <cclauss@me.com>
for more information, see https://pre-commit.ci
tianyizheng02
requested changes
Aug 1, 2023
Comment on lines
+5
to
+11
| T = 300 # TEMPERATURE (unit = K) | ||
|
|
||
|
|
||
| def forward_bias_current( | ||
| forward_voltage: float, | ||
| reverse_saturation_current: float, | ||
| ) -> float: |
Contributor
There was a problem hiding this comment.
Why not just make the temperature a parameter?
Suggested change
| T = 300 # TEMPERATURE (unit = K) | |
| def forward_bias_current( | |
| forward_voltage: float, | |
| reverse_saturation_current: float, | |
| ) -> float: | |
| def forward_bias_current( | |
| forward_voltage: float, | |
| reverse_saturation_current: float, | |
| temp_kelvin: float = 300.0 | |
| ) -> float: |
| @@ -0,0 +1,52 @@ | |||
| from math import e | |||
Contributor
There was a problem hiding this comment.
Suggested change
| from math import e | |
| from math import exp |
math has an exp function that's "usually more accurate than math.e ** x or pow(math.e, x)" according to Python docs.
| @@ -0,0 +1,52 @@ | |||
| from math import e | |||
|
|
|||
| from scipy.constants import Boltzmann, physical_constants | |||
Contributor
There was a problem hiding this comment.
Suggested change
| from scipy.constants import Boltzmann, physical_constants | |
| from scipy import constants |
constants already has an easy way to get the value of constants without needing to access the underlying physical_constants dict: constants.get()
Member
There was a problem hiding this comment.
These are constants. Is there a good reason to pay the function call overhead of using .get()?
Comment on lines
+32
to
+46
| if forward_voltage < 0: | ||
| raise ValueError("Forward voltage cannot be negative") | ||
| elif reverse_saturation_current <= 0: | ||
| raise ValueError("Reverse saturation current should be positive") | ||
| elif reverse_saturation_current > 1e-5: | ||
| raise ValueError("Reverse saturation current cannot be greater than 1e-5") | ||
| else: | ||
| return reverse_saturation_current * ( | ||
| e | ||
| ** ( | ||
| (forward_voltage * physical_constants["electron volt"][0]) | ||
| / (Boltzmann * T) | ||
| ) | ||
| - 1 | ||
| ) |
Contributor
There was a problem hiding this comment.
Suggested change
| if forward_voltage < 0: | |
| raise ValueError("Forward voltage cannot be negative") | |
| elif reverse_saturation_current <= 0: | |
| raise ValueError("Reverse saturation current should be positive") | |
| elif reverse_saturation_current > 1e-5: | |
| raise ValueError("Reverse saturation current cannot be greater than 1e-5") | |
| else: | |
| return reverse_saturation_current * ( | |
| e | |
| ** ( | |
| (forward_voltage * physical_constants["electron volt"][0]) | |
| / (Boltzmann * T) | |
| ) | |
| - 1 | |
| ) | |
| if forward_voltage < 0: | |
| raise ValueError("Forward voltage cannot be negative") | |
| if reverse_saturation_current <= 0: | |
| raise ValueError("Reverse saturation current must be positive") | |
| if reverse_saturation_current > 1e-5: | |
| raise ValueError("Reverse saturation current cannot be greater than 1e-5") | |
| return reverse_saturation_current * ( | |
| exp( | |
| forward_voltage * constants.get("electron volt") | |
| / (constants.k * temp_kelvin) | |
| ) - 1 | |
| ) |
cclauss
reviewed
Aug 1, 2023
Comment on lines
+13
to
+14
| This function can calculate the Forward Bias Current of a pn junction diode. | ||
| This is calculated from the given two values. |
Member
There was a problem hiding this comment.
Suggested change
| This function can calculate the Forward Bias Current of a pn junction diode. | |
| This is calculated from the given two values. | |
| Calculate the Forward Bias Current of a pn junction diode from given two values. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.