我必须定义两个单独的函数 z(x, mu, c)
和 landau(x, A, mu, c)
。
z = (x-mu)/c
和 landau = 1.64872*A*np.exp(-0.5(z+np.exp(-z)))
当他们共享变量时,我试图在 z
的定义中将 landau
定义为函数本身而不是函数。此外,我尝试将 z
定义为 landau
定义之外的函数。但是,我尝试的任何方法似乎都不起作用。 python 告诉我 "'float' object is not callable"
或 "bad operant type for unary -: 'function'"
。有没有快速解决方法?
landau(1,1,1,1)
应该给出一个大致等于 1 的答案
def landau(x, A, mu, c): # Functie Landau met variabelen x, A, c en mu
# A = amplitude
# c = schaalparameter
# mu = positieparameter
def z(x, mu, c):
return (x-mu)/c
return 1.64872*A*np.exp(-0.5(z(x, mu, c)+np.exp(-z(x, mu, c))))
答案 0 :(得分:2)
您错过了 -0.5 * (z(x
中的 *。至少我假设它应该是乘法。
import numpy as np
def landau(x, A, mu, c): # Functie Landau met variabelen x, A, c en mu
# A = amplitude
# c = schaalparameter
# mu = positieparameter
return 1.64872 * A * np.exp(-0.5 * (z(x, mu, c) + np.exp(-z(x, mu, c))))
def z(x, mu, c):
return (x - mu) / c
landau(1, 1, 1, 1)
0.9999992292814129