给出logistics的python代码
时间: 2023-11-12 22:12:09 浏览: 80
logistics回归代码预测中国人口
当然可以,以下是一个简单的logistics模型的Python代码:
```python
import numpy as np
def logistic(t, K, r, P0):
"""
Compute the logistic function for population growth. Takes as inputs:
t : array-like list or array of times
K : float, carrying capacity of population
r : float, population growth rate
P0 : int, initial population size
"""
exp_func = np.exp(r * t)
return K * P0 * exp_func / (K + P0 * (exp_func - 1))
# Example usage
t = np.linspace(0, 10, 100)
K = 10000
r = 0.1
P0 = 5000
population = logistic(t, K, r, P0)
```
阅读全文