import numpy as np #for basic numerical computation import matplotlib.pyplot as plt #for visualization import csv import random #val = int(input("Enter your value: ")) r = .25 # growth rate / year ,|(birth/death rate) K = 100 # carrying capacity #t = 40 # time t=random.randint(0,40) num = np.zeros(t+1)#always add +1 for your upper limit #array([ 0., 0., 0., 0., 0.]) which means that it creates 41 arrays filled with zeroes num[0] = 1 for i in range(t): num[i+1] = num[i]+r*num[i]*(1-num[i]/K) row= (i+1,'\t\t',format(num[i], '.8f')) print (row) with open('plot.csv', 'a') as csvFile: writer = csv.writer(csvFile, delimiter=' ') writer.writerow(row) csvFile.close() plt.plot(range(t+1),num, 'b') plt.xlabel('Time') plt.ylabel(' Cell Number') plt.title('Logistic Growth') plt.axvline(np.argmax(np.diff(num)), color = 'k' ) plt.show()
t=float(random.randint(0,40))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)