我想使用包含Langevin函数和对分布函数[1]的磁模型来拟合具有超顺磁行为的滞后曲线。为了符合这个等式,我必须解决一个明确的积分。我试图使用scipy.integrate.quad用于此目的和lmfit的功能,但我没有得到 - 至少 - 模拟一个合理的曲线(见下面的代码)。可用于模拟该等式的一些实际物理参数是:Dm = 3.2E-9m,w = 0.26,NT = 1.7E12,kB = 1.38E-23J / K且T = 300K。用这个值模拟它必须产生如下面链接中所包含的超顺磁曲线。我将不胜感激任何建议使这段代码工作并改进它。
www.dropbox.com/pri/get/superpara.dat?_subject_uid=197016565&w=AADkHqW1w-gE9pQkG0oLoE7tNG1J-rWxN0lcIM9ioXWiLA
from lmfit import minimize, Minimizer, Parameters, Parameter, report_fit
from numpy import loadtxt, vectorize, sqrt, log, log10, inf, exp, pi, tanh
from scipy.integrate import quad
import matplotlib.pyplot as plt
dat = loadtxt('superpara.dat')
u0_H = dat[:, 0]
dat1 = dat[:, 1]
def PDF(Dmag, u0_H, params):
v = params.valuesdict()
pdf = (1/(v['w']*sqrt(2*pi)*Dmag))*exp(-(log(Dmag/v['Dm']))**2 / (2*v['w']**2))
x = (pi/(6*v['kB']*v['T']))*v['Ms']*(u0_H*1e-4)*Dmag**3
return (pi/6)*v['Ms']*(Dmag**3)*( (1/tanh(x))-(1/x) )*pdf
def curve(u0_H, params):
return params['NT']*quad(PDF, 0.0, inf, args=(u0_H, params))[0]
vcurve = vectorize(curve, excluded=set([1]))
def fit_function(params, u0_H, dat1):
model1 = vcurve(u0_H, params)
resid1 = dat1 - model1
return resid1.flatten()
params = Parameters()
params.add('Dm' , value= 3.2e-9 , vary= True)
params.add('w' , value= 0.26 , vary= True)
params.add('Ms' , value= 0.1 , vary= True)
params.add('T' , value= 300 , vary= False)
params.add('kB' , value= 1.38e-23, vary= False)
params.add('NT' , value= 1.7e12 , vary= True)
minner = Minimizer(fit_function, params, fcn_args=(u0_H, dat1))
result = minner.minimize()
report_fit(result)
y1_fit = vcurve(u0_H, result.params)
y1_init = vcurve(u0_H, params)
plt.plot(u0_H, dat1, 'k+', u0_H, y1_init, 'b-', u0_H, y1_fit, 'r-')
plt.show()