我知道有与此有关的线程,但我很困惑,我想让我的数据适合我的数据。Python - 从记录值拟合指数衰减曲线
我的数据被导入并绘制成这样。
import matplotlib.pyplot as plt
%matplotlib inline
import pylab as plb
import numpy as np
import scipy as sp
import csv
FreqTime1 = []
DecayCount1 = []
with open('Half_Life.csv', 'r') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
FreqTime1.append(row[0])
DecayCount1.append(row[3])
FreqTime1 = np.array(FreqTime1)
DecayCount1 = np.array(DecayCount1)
fig1 = plt.figure(figsize=(15,6))
ax1 = fig1.add_subplot(111)
ax1.plot(FreqTime1,DecayCount1, ".", label = 'Run 1')
ax1.set_xlabel('Time (sec)')
ax1.set_ylabel('Count')
plt.legend()
问题是,我遇到困难设置常规指数衰减,在我不知道如何从数据集中计算的参数值。
如果可能的话,那么我想要用图表显示拟合衰减方程的方程。但是,如果能够生产出适合的产品,这可以很容易地应用。
编辑 ------------------------------------------- ------------------
所以使用Stanely基R提及
def model_func(x, a, k, b):
return a * np.exp(-k*x) + b
x = FreqTime1
y = DecayCount1
p0 = (1.,1.e-5,1.)
opt, pcov = curve_fit(model_func, x, y, p0)
a, k, b = opt
我与此错误消息
返回的拟合函数时TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32') dtype('S32') dtype('S32')
有关如何解决此问题的任何想法?
看看http://stackoverflow.com/questions/21420792/exponential-curve-fitting-in-scipy –