Skip to content

Added forward bias voltage#7871

Closed
sadiqebrahim wants to merge 7 commits intoTheAlgorithms:masterfrom
sadiqebrahim:master
Closed

Added forward bias voltage#7871
sadiqebrahim wants to merge 7 commits intoTheAlgorithms:masterfrom
sadiqebrahim:master

Conversation

@sadiqebrahim
Copy link
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 30, 2022
@cclauss cclauss added the ON HOLD: Final hours of Hacktoberfest We will review this PR after Hacktoberfest has ended label Oct 30, 2022
Copy link
Contributor

@CaedenPH CaedenPH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
@CaedenPH
Copy link
Contributor

@cclauss I know this is on hold but its a pretty quick and easy one to merge

sadiqebrahim and others added 2 commits October 30, 2022 18:50
Co-authored-by: Christian Clauss <cclauss@me.com>
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 30, 2022
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 30, 2022
@sadiqebrahim sadiqebrahim requested a review from cclauss October 30, 2022 13:30
@cclauss cclauss removed the ON HOLD: Final hours of Hacktoberfest We will review this PR after Hacktoberfest has ended label Nov 1, 2022
Comment on lines +5 to +11
T = 300 # TEMPERATURE (unit = K)


def forward_bias_current(
forward_voltage: float,
reverse_saturation_current: float,
) -> float:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@tianyizheng02 tianyizheng02 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
)
Copy link
Contributor

@tianyizheng02 tianyizheng02 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
)

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cclauss cclauss closed this Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants