fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.integrate import odeint
  4.  
  5. # Define the system of equations
  6. def feedback_system(y, t, params):
  7. x1, x2, x3 = y
  8. a1, a2, a3, a4, a5, a6, k1, k2, k3, w1, w2 = params
  9.  
  10. dx1dt = 1 + a1 * x1 * (1 - x1) - (x1 * x2) / (w1 + x1) - k1 * x1
  11. dx2dt = (a2 * x2 * x3) / (w2 + x3) - a3 * x2 + k2 * x2
  12. dx3dt = a4 * x3 * (1 - x3) - (a5 * x2 * x3) / (w2 + x3) - a6 * x3 + k3 * x3
  13.  
  14. return [dx1dt, dx2dt, dx3dt]
  15.  
  16. # Parameters
  17. params = [0.1, 0.05, 0.1, 0.1, 0.01, 0.1, 0.2, 0.1, 0.1, 1, 1] # a1, a2, a3, a4, a5, a6, k1, k2, k3, w1, w2
  18.  
  19. # Initial conditions
  20. x1_0 = 5 # Initial population of tumor cells
  21. x2_0 = 2 # Initial population of hunting cells
  22. x3_0 = 0.5 # Initial population of resting cells
  23.  
  24. # Time points
  25. t = np.linspace(0, 100, 1000)
  26.  
  27. # Solve ODEs
  28. initial_conditions = [x1_0, x2_0, x3_0]
  29. solution = odeint(feedback_system, initial_conditions, t, args=(params,))
  30. x1, x2, x3 = solution.T
  31.  
  32. # Plot results
  33. plt.figure(figsize=(10, 6))
  34. plt.plot(t, x1, label='Tumor Cells (x1)', color='blue')
  35. plt.plot(t, x2, label='Hunting Cells (x2)', color='orange')
  36. plt.plot(t, x3, label='Resting Cells (x3)', color='green')
  37. plt.title('Dynamics of Tumor and Immune Cells Over Time')
  38. plt.xlabel('Time')
  39. plt.ylabel('Population')
  40. plt.legend()
  41. plt.grid()
  42. plt.show()
  43.  
Success #stdin #stdout 0.84s 68236KB
stdin
Standard input is empty
stdout
Standard output is empty