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

# Define the system of equations
def feedback_system(y, t, params):
    x1, x2, x3 = y
    a1, a2, a3, a4, a5, a6, k1, k2, k3, w1, w2 = params
    
    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]

# Parameters
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

# Initial conditions
x1_0 = 5   # Initial population of tumor cells
x2_0 = 2   # Initial population of hunting cells
x3_0 = 0.5 # Initial population of resting cells

# Time points
t = np.linspace(0, 100, 1000)

# Solve ODEs
initial_conditions = [x1_0, x2_0, x3_0]
solution = odeint(feedback_system, initial_conditions, t, args=(params,))
x1, x2, x3 = solution.T

# Plot results
plt.figure(figsize=(10, 6))
plt.plot(t, x1, label='Tumor Cells (x1)', color='blue')
plt.plot(t, x2, label='Hunting Cells (x2)', color='orange')
plt.plot(t, x3, label='Resting Cells (x3)', color='green')
plt.title('Dynamics of Tumor and Immune Cells Over Time')
plt.xlabel('Time')
plt.ylabel('Population')
plt.legend()
plt.grid()
plt.show()
