正在思考中,,,,,,,,,

import numpy as np
import matplotlib.pyplot as plt
import math
import pandas as pd
from scipy.optimize import curve_fit
from scipy import log



#表示函数表达式
def logistic_increase_function(t,K,P0,r):
    P0 = 35
    K = 1722
    t0 = 0
    exp_value=np.exp(r*(t-t0))
    return (K*exp_value*P0)/(K+(exp_value-1)*P0)



#键入日期以及草履虫数
t=[0, 1, 2, 3, 4, 5, 6, 7, 8]
P=[35, 50, 120, 210, 650, 1230, 1620, 1710, 1760]



#创建向量类型
t=np.array(t)
P=np.array(P)




# 用最小二乘法估计拟合
popt, pcov = curve_fit(logistic_increase_function, t, P)

#获取popt里面是拟合系数
# print("K:环境容纳量  P0:初始草履虫数量   r:瞬时增长速率   t:时间")

'''
生物知识补充:
K为环境容量,即增长到最后,P(t)能达到的极限。
P0为初始容量,就是t=0时刻的数量。
r为增长速率,r越大则增长越快,越快逼近K值,r越小增长越慢,越慢逼近K值。
'''

print(popt)
#拟合后预测的P值
P_predict = logistic_increase_function(t,popt[0],popt[1],popt[2])
#未来预测
# future=[11,18,19,20 ,21, 22, 23, 24,  25,  26,  27,28,29,30,31,41,51,61,71,81,91,101]
# future=np.array(future)
# future_predict=logistic_increase_function(future,popt[0],popt[1],popt[2])
#近期情况预测
# tomorrow=[28,29,30,32,33,35,37,40]
# tomorrow=np.array(tomorrow)
# tomorrow_predict = logistic_increase_function(tomorrow,popt[0],popt[1],popt[2])
 
#绘图
plot1 = plt.plot(t, P, 's',label="confimed infected people number")
plot2 = plt.plot(t, P_predict, 'r',label='predict infected people number')
# plot3 = plt.plot(tomorrow, tomorrow_predict, 's',label='predict infected people number')
plt.xlabel('time')
plt.ylabel('confimed infected people number')
 
plt.legend(loc=0) #指定legend的位置右下角
 
# print(logistic_increase_function(np.array(28),popt[0],popt[1],popt[2]))
# print(logistic_increase_function(np.array(29),popt[0],popt[1],popt[2]))
plt.show()
 
 
#未来预测绘图
#plot2 = plt.plot(t, P_predict, 'r',label='polyfit values')
#plot3 = plt.plot(future, future_predict, 'r',label='polyfit values')
#plt.show()
 
 
print("Program done!")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

终是蝶衣梦晓楼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值