import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

# Define parameters
a1 = 2.0   # Growth rate of tumor cells
a2 = 0.5   # Growth rate of hunting cells
a3 = 0.1   # Death rate of hunting cells
a4 = 1.0   # Growth rate of resting cells
a5 = 0.1   # Interaction term between hunting and resting cells
a6 = 0.1   # Death rate of resting cells
w1 = 0.5   # Half-saturation constant for tumor cells
w2 = 0.5   # Half-saturation constant for hunting cells
k1 = 0.5   # Feedback control coefficient for tumor cells
k2 = 0.1   # Feedback control coefficient for hunting cells
k3 = 0.1   # Feedback control coefficient for resting cells

# Define the system of equations
def model(y, t):
    x1, x2, x3 = y
    dx1dt = 1 + a1 * x1 * (1 - x1) - (x1 * x2) / (w1 + x1) - k1 * x1
    dx2dt = (a2 * x2 * x3) / (w2 + x3) - a3 * x2 + k2 * x2
    dx3dt = a4 * x3 * (1 - x3) - (a5 * x2 * x3) / (w2 + x3) - a6 * x3 + k3 * x3
    return [dx1dt, dx2dt, dx3dt]

# Initial conditions: [tumor cells, hunting cells, resting cells]
initial_conditions = [0.1, 0.5, 0.5]

# Time points where solution is computed
t = np.linspace(0, 50, 500)

# Solve ODEs
solution = odeint(model, initial_conditions, t)

# Plot the results
plt.figure(figsize=(10, 6))
plt.plot(t, solution[:, 0], label='Tumor Cells (x1)', color='r')
plt.plot(t, solution[:, 1], label='Hunting Cells (x2)', color='g')
plt.plot(t, solution[:, 2], label='Resting Cells (x3)', color='b')
plt.title('Feedback System Dynamics')
plt.xlabel('Time')
plt.ylabel('Cell Population')
plt.legend()
plt.grid()
plt.show()