print (scipy.constants.physical_constants ["hyperfine transition frequency of Cs-133 "])
and print (scipy.constants.physical_constants ["luminous efficacy "])
are output as empty strings. In that case, an update is required. SciPy 1.4.0 Release Notes — SciPy v1.5.4 Reference Guide
Physical constants can be introduced by doing from scipy.constants import *
.
SI_2019
from scipy.constants import *
print(physical_constants["hyperfine transition frequency of Cs-133"])
print(c) #speed of light in vacuum
print(h) #the Planck constant
print(e) #elementary charge
print(k) #Boltzmann constant
print(N_A) #Avogadro constant
print(physical_constants["luminous efficacy"])
This is the output result.
Results
(9192631770.0, 'Hz', 0.0)
299792458.0
6.62607015e-34
1.602176634e-19
1.380649e-23
6.02214076e+23
(683.0, 'lm W^-1', 0.0)
If you say from scipy import constants
, you have to do something like constants.h
or scipy.constant.physical_constants ["hyperfine transition frequency of Cs-133 "]
, but you get the same result. ..
from scipy import constants
print(constants.h)
#6.62607015e-34
In addition, various units such as combined units can also be used in calculations.
units
from scipy.constants import *
print(day) #one day is 86400 seconds
print(gram) # one gram is 0.001 kilogram
print(eV) #1 eV equals e coulomb times 1 volt
#86400.0
#0.001
#1.602176634e-19
Unit calculation using a prefix is also possible. You can also convert the wavelength-frequency of electromagnetic waves by using lambda2nu ()
.
prefix_and_lambda2nu
print('{:e}'.format(lambda2nu(370 * nano)), 'Hz') #ultraviolet
print(lambda2nu(370 * nano) / tera, 'THz')
print('{:e}'.format(lambda2nu(1 * milli)), 'Hz') #radio waves (microwaves)
print(lambda2nu(1 * milli) / giga, 'GHz')
#8.102499e+14 Hz
#810.2498864864865 THz
#2.997925e+11 Hz
#299.792458 GHz
Elementary charges and Napier numbers are confusing because they both have the same symbol, $ e $ [^ 2].
[^ 2]: There is also a style of making it three-dimensional like e
and i
, but this is not the case in all cases, but rather italics are customarily used.
If you just want to print it, you can add an annotation, but you cannot use the same name in the code.
from scipy.constants import *
print(physical_constants["elementary charge"])
print(e)
print(math.e) #the Euler's number
Especially in LaTeX, you don't type math.e
, so it's very troublesome to copy a cleanly written formula to Python code.
Preparation
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import math
from scipy.constants import *
Consider the Fermi-Dirac distribution as an example of the appearance of exponents. Suppose you want to plot a graph of the following formula:
\frac{1}{e^{\beta(\varepsilon - \mu)} + 1}= \frac{1}{e^{\mu(x - 1)/(kT)} + 1}\quad(x = \varepsilon/ \mu )
Where $ k $ is the Boltzmann constant. Let's draw with Jupyter notebook.
Fermi_Dirac_distribution
from scipy.constants import *
def E(x, mu):
return 1/(e**(mu*(x - 1)/(k*T)) + 1)
That is a strange graph (the graph drawing settings are omitted). This is a qualitatively impossible graph because the particles can take as much energy as possible. Since e
is defined as the value of the elementary charge infrom scipy.constants import *
, the graph was output, but the calculation was incorrect.
Of course, you can play with import
to solve the problem, but here we will use the most intuitive, convenient, and convenient method. In other words, now according to the formula
e = math.e
Let's do it. Since the elementary charge is not used in this calculation, there is no problem locally (if the elementary charge is used elsewhere, write from scipy.constants import *
again at that time, etc. You should do it).
from scipy.constants import *
e = math.e
def E(x, mu):
return 1/(e**(mu*(x - 1)/(k*T)) + 1)
The correct graph is output!
Constants (scipy.constants) — SciPy v1.5.3 Reference Guide
[SciPy Constants]
(https://www.w3schools.com/python/scipy_constants.asp)
[Python math.e Constant]
(https://www.w3schools.com/python/ref_math_e.asp)
[python memo]
(http://tomohiro_abe.droppages.com/misc/python.html) I referred to from scipy.constants import *
.
[Fermi–Dirac statistics - Wikipedia]
(https://en.wikipedia.org/wiki/Fermi–Dirac_statistics) I referred to the Fermi-Dirac statistics.
Recommended Posts