@@ -59,6 +59,45 @@ 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
+
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
62
101
63
102
64
103
if __name__ == "__main__" :
0 commit comments