fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.integrate import odeint
  4.  
  5. # Define parameters
  6. a1 = 2.0 # Growth rate of tumor cells
  7. a2 = 0.5 # Growth rate of hunting cells
  8. a3 = 0.1 # Death rate of hunting cells
  9. a4 = 1.0 # Growth rate of resting cells
  10. a5 = 0.1 # Interaction term between hunting and resting cells
  11. a6 = 0.1 # Death rate of resting cells
  12. w1 = 0.5 # Half-saturation constant for tumor cells
  13. w2 = 0.5 # Half-saturation constant for hunting cells
  14. k1 = 0.5 # Feedback control coefficient for tumor cells
  15. k2 = 0.1 # Feedback control coefficient for hunting cells
  16. k3 = 0.1 # Feedback control coefficient for resting cells
  17.  
  18. # Define the system of equations
  19. def model(y, t):
  20. x1, x2, x3 = y
  21. dx1dt = 1 + a1 * x1 * (1 - x1) - (x1 * x2) / (w1 + x1) - k1 * x1
  22. dx2dt = (a2 * x2 * x3) / (w2 + x3) - a3 * x2 + k2 * x2
  23. dx3dt = a4 * x3 * (1 - x3) - (a5 * x2 * x3) / (w2 + x3) - a6 * x3 + k3 * x3
  24. return [dx1dt, dx2dt, dx3dt]
  25.  
  26. # Initial conditions: [tumor cells, hunting cells, resting cells]
  27. initial_conditions = [0.1, 0.5, 0.5]
  28.  
  29. # Time points where solution is computed
  30. t = np.linspace(0, 50, 500)
  31.  
  32. # Solve ODEs
  33. solution = odeint(model, initial_conditions, t)
  34.  
  35. # Plot the results
  36. plt.figure(figsize=(10, 6))
  37. plt.plot(t, solution[:, 0], label='Tumor Cells (x1)', color='r')
  38. plt.plot(t, solution[:, 1], label='Hunting Cells (x2)', color='g')
  39. plt.plot(t, solution[:, 2], label='Resting Cells (x3)', color='b')
  40. plt.title('Feedback System Dynamics')
  41. plt.xlabel('Time')
  42. plt.ylabel('Cell Population')
  43. plt.legend()
  44. plt.grid()
  45. plt.show()
Success #stdin #stdout 0.96s 67936KB
stdin
Standard input is empty
stdout
Standard output is empty