【发布时间】:2013-02-08 06:19:53
【问题描述】:
我正在尝试用 Python 重现这个 Mathematica 程序:
它找到数值积分的根,并形成这些值的图。但是,我无法尝试运行。
当前尝试:
从 scipy.integrate 导入四边形 从 scipy 导入集成 从 scipy.optimize 导入 fsolve 将pylab导入为pl 将 numpy 导入为 np
# Variables.
boltzmann_const = 1.38e-23
planck_const = 6.62e-34
hbar = planck_const / ( 2 * np.pi )
transition_temp = 9.2
gap_energy_at_zero_kelvin = 3.528 / ( 2 * transition_temp * boltzmann_const )
debye_freq = ( 296 * boltzmann_const ) / hbar
# For subtracting from root_of_integral
a_const = np.log( ( 1.13 * hbar * debye_freq ) / ( boltzmann_const * transition_temp) )
# For simplifying function f.
b_const = ( hbar * debye_freq ) / ( 2 * boltzmann_const)
def f( coherence_length, temp ):
# Defines the equation whose integral will have its roots found. Epsilon = coherence length. Delta = Gap energy.
squareRoot = np.sqrt( coherence_length*coherence_length + gap_energy*gap_energy )
return np.tanh( ( ( b_const / temp ) * squareRoot ) / squareRoot )
def integrate( coherence_length, temp ):
# Integrates equation f with respect to E, between 0 and 1.
return integrate.quad( f, 0, 1, args = ( temp, ) )[0]
def root_of_integral( temp ):
# Finds the roots of the integral with a guess of 0.01.
return fsolve( integrate, 0.01, args = ( temp, ) )
def gap_energy_values( temp ):
# Subtracts a_const from each root found, to obtain the gap_energy_values.
return root_of_integral( temp ) - a_const
【问题讨论】:
-
解释器给出的错误信息可能有用吗?
-
请定义“无法运行”。另外,使用这种文字:
1.38e-23、6.62e-34、1e-23。 -
相应编辑,谢谢!
标签: python numpy scipy physics numerical-integration