Skip to content

Commit 5fed8e9

Browse files
authored
Update photoelectric_effect.py
added work function calculation
1 parent 03a4251 commit 5fed8e9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

physics/photoelectric_effect.py

+39
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,45 @@ def maximum_kinetic_energy(
5959
if in_ev:
6060
return max(PLANCK_CONSTANT_EVS * frequency - work_function, 0)
6161
return max(PLANCK_CONSTANT_JS * frequency - work_function, 0)
62+
63+
def work_function(
64+
frequency: float, kinetic_energy: float, in_ev: bool = False
65+
) -> float:
66+
"""
67+
Calculates the work function of a surface using the given
68+
frequency and kinetic energy.
69+
70+
Parameters:
71+
frequency (float): Frequency of the electromagnetic wave.
72+
kinetic_energy (float): Kinetic energy of emitted electron.
73+
in_ev (bool, optional): True if frequency and
74+
kinetic energy are in eV.
75+
76+
Returns:
77+
float: The calculated work function of the surface.
78+
79+
Raises:
80+
ValueError: If the frequency is negative.
81+
82+
Usage example:
83+
>>> work_function(1e6, 2)
84+
-6.62607015e-28
85+
>>> work_function(1e6, 2, True)
86+
-8.271335392e-09
87+
>>> work_function(1e16, 39.357, True)
88+
24.542
89+
>>> work_function(-9, 20)
90+
Traceback (most recent call last):
91+
...
92+
ValueError: Frequency can't be negative.
93+
"""
94+
95+
if frequency < 0:
96+
raise ValueError("Frequency can't be negative.")
97+
98+
if in_ev:
99+
return PLANCK_CONSTANT_EVS * frequency - kinetic_energy
100+
return PLANCK_CONSTANT_JS * frequency - kinetic_energy
62101

63102

64103
if __name__ == "__main__":

0 commit comments

Comments
 (0)