t=float(random.randint(0,40))

15,664,272 members

See more:

I have to code the logistic growth in python where time can take float numbers.

**dN/dt = rN(1-N/K)**

where

**N** is the population

**r** is the growth rate

**K** is the carrying capacity

**t** is the time

The**time** in my code can take only integers but it must definitely take float numbers as later I will use it for the logistic growth of the tumours and I couldn't fix it.

I will really appreciate all the help possible even if it is not related to my code.

**What I have tried:**

where

The

I will really appreciate all the help possible even if it is not related to my code.

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()

Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

I have to input float numbers to t(time)for example 0.01. The problem is this code can't take float values. I am a beginner in python and can't figure out how to fix it.