Skip to content

Commit 94b51f6

Browse files
sadiqebrahimCaedenPHpre-commit-ci[bot]cclauss
authored
Added Builtin Voltage (TheAlgorithms#7850)
* Added Builtin Voltage * Update builtin_voltage.py * Update electronics/builtin_voltage.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * Update electronics/builtin_voltage.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Create elf.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent ab9d8f3 commit 94b51f6

File tree

2 files changed

+73
-8
lines changed

2 files changed

+73
-8
lines changed

electronics/builtin_voltage.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from math import log
2+
3+
from scipy.constants import Boltzmann, physical_constants
4+
5+
T = 300 # TEMPERATURE (unit = K)
6+
7+
8+
def builtin_voltage(
9+
donor_conc: float, # donor concentration
10+
acceptor_conc: float, # acceptor concentration
11+
intrinsic_conc: float, # intrinsic concentration
12+
) -> float:
13+
"""
14+
This function can calculate the Builtin Voltage of a pn junction diode.
15+
This is calculated from the given three values.
16+
Examples -
17+
>>> builtin_voltage(donor_conc=1e17, acceptor_conc=1e17, intrinsic_conc=1e10)
18+
0.833370010652644
19+
>>> builtin_voltage(donor_conc=0, acceptor_conc=1600, intrinsic_conc=200)
20+
Traceback (most recent call last):
21+
...
22+
ValueError: Donor concentration should be positive
23+
>>> builtin_voltage(donor_conc=1000, acceptor_conc=0, intrinsic_conc=1200)
24+
Traceback (most recent call last):
25+
...
26+
ValueError: Acceptor concentration should be positive
27+
>>> builtin_voltage(donor_conc=1000, acceptor_conc=1000, intrinsic_conc=0)
28+
Traceback (most recent call last):
29+
...
30+
ValueError: Intrinsic concentration should be positive
31+
>>> builtin_voltage(donor_conc=1000, acceptor_conc=3000, intrinsic_conc=2000)
32+
Traceback (most recent call last):
33+
...
34+
ValueError: Donor concentration should be greater than intrinsic concentration
35+
>>> builtin_voltage(donor_conc=3000, acceptor_conc=1000, intrinsic_conc=2000)
36+
Traceback (most recent call last):
37+
...
38+
ValueError: Acceptor concentration should be greater than intrinsic concentration
39+
"""
40+
41+
if donor_conc <= 0:
42+
raise ValueError("Donor concentration should be positive")
43+
elif acceptor_conc <= 0:
44+
raise ValueError("Acceptor concentration should be positive")
45+
elif intrinsic_conc <= 0:
46+
raise ValueError("Intrinsic concentration should be positive")
47+
elif donor_conc <= intrinsic_conc:
48+
raise ValueError(
49+
"Donor concentration should be greater than intrinsic concentration"
50+
)
51+
elif acceptor_conc <= intrinsic_conc:
52+
raise ValueError(
53+
"Acceptor concentration should be greater than intrinsic concentration"
54+
)
55+
else:
56+
return (
57+
Boltzmann
58+
* T
59+
* log((donor_conc * acceptor_conc) / intrinsic_conc**2)
60+
/ physical_constants["electron volt"][0]
61+
)
62+
63+
64+
if __name__ == "__main__":
65+
import doctest
66+
67+
doctest.testmod()

hashes/elf.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ def elf_hash(data: str) -> int:
22
"""
33
Implementation of ElfHash Algorithm, a variant of PJW hash function.
44
5-
Returns:
6-
[int] -- [32 bit binary int]
75
>>> elf_hash('lorem ipsum')
86
253956621
97
"""
10-
hash = x = 0
8+
hash_ = x = 0
119
for letter in data:
12-
hash = (hash << 4) + ord(letter)
13-
x = hash & 0xF0000000
10+
hash_ = (hash_ << 4) + ord(letter)
11+
x = hash_ & 0xF0000000
1412
if x != 0:
15-
hash ^= x >> 24
16-
hash &= ~x
17-
return hash
13+
hash_ ^= x >> 24
14+
hash_ &= ~x
15+
return hash_
1816

1917

2018
if __name__ == "__main__":

0 commit comments

Comments
 (0)