请允许我首先介绍问题的背景:
然后询问该模型是否可以线性化,如果可以,则使用线性模型来评估a
和k
的值
t = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
y = np.array([43.65, 109.86, 187.21, 312.67, 496.58, 707.65, 960.25, 1238.75, 1560, 1824.29, 2199, 2438.89, 2737.71])
yAss = np.log(3000/y - 1)
cof = np.polyfit(t, yAss, deg = 1)
a = math.e**(cof[0]);
k = -cof[1];
yAfter = 3000 / (1 + a*math.e**(-k*t))
sizeScalar = 10
fig = plt.figure(figsize = (sizeScalar*1.1, sizeScalar))
plt.plot(t, y, 'o', markersize = sizeScalar*0.75)
plt.plot(t, yAfter, 'r-')
plt.grid(True)
plt.show()
t = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
y = np.array([43.65, 109.86, 187.21, 312.67, 496.58, 707.65, 960.25, 1238.75, 1560, 1824.29, 2199, 2438.89, 2737.71])
yAss = np.log(3000/y - 1)
cof = np.polyfit(t, yAss, deg = 1)
a = math.e**(-cof[1]); #<<<===============here. Before: a = math.e**(cof[0])
k = cof[0]; #<<<==========================and here, Before: k = -cof[1]
temp = 3000 / (1 + a*math.e**(-k*t))
yAfter = []
for itera in temp: #<<<=======================add this
yAfter.append(3000 - itera)
sizeScalar = 10
fig = plt.figure(figsize = (sizeScalar*1.1, sizeScalar))
plt.plot(t, y, 'o', markersize = sizeScalar*0.75)
plt.plot(t, yAfter, 'r-')
plt.grid(True)
plt.show()
收到了一个似乎正确的序列?
但怎么可能呢?我认为cof[0]是beta,cof1是-k
,如果是,我以前的代码应该有一些错误的概念。但是改变系数的顺序和符号,我得到了一个很合适的结果?!这纯粹是巧合吗?
那么测验的正确答案是什么呢
np.polyfit
首先返回最高阶:https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html#numpy.polyfit用途:
此外,您还可以使用NumPy的指数:
相关问题 更多 >
编程相关推荐