Skip to content

Instantly share code, notes, and snippets.

@codemicro
Created January 20, 2021 12:17
Show Gist options
  • Save codemicro/02b8115faa6bcedd26e88516027c102c to your computer and use it in GitHub Desktop.
Save codemicro/02b8115faa6bcedd26e88516027c102c to your computer and use it in GitHub Desktop.
import math
plancks_constant = 6.63e-34
speed_of_light = 3e8
joules_per_electronvolt = 1.6e-19
meters_per_nanometer = 1e-9
mass_of_electron_kg = 9.109e-31
def wavelength_to_ephoton(nanometers):
# returns joules
return frequency_to_ephoton(speed_of_light / (nanometers * meters_per_nanometer))
def frequency_to_ephoton(hertz):
# returns joules
return plancks_constant * hertz
def ephoton_to_frequency(joules):
# returns hertz
return joules / plancks_constant
def joules_to_electronvolts(joules):
# returns joules
return joules / joules_per_electronvolt
def electronvolts_to_joules(electronvolts):
# returns joules
return joules_per_electronvolt * electronvolts
def work_function_to_threshold_frequency(electronvolts):
# returns hertz
wfj = electronvolts_to_joules(electronvolts)
return ephoton_to_frequency(wfj)
def wavelength_to_work_function(nanometers):
# returns electronvolts
return joules_to_electronvolts(wavelength_to_ephoton(nanometers))
def max_speed_from_work_function_and_frequency(joules, hertz):
# returns meters per second
ephoton = frequency_to_ephoton(hertz)
ekmax = ephoton - joules
return math.sqrt(ekmax / (0.5 * mass_of_electron_kg))
# n = max_speed_from_work_function_and_frequency(8.4e-20, 7e14)
# print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment