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