!pip install qutip


import numpy as np
from qutip import *

# Define the system parameters
omega = 1.0  # Frequency of the external potential
interaction_strength = 0.5  # Strength of the interaction
time_points = np.linspace(0, 10, 1000)  # Time points for simulation

# Define the Hamiltonian for the system
H0 = omega * tensor(sigmax(), identity(2))  # External potential
Hint = interaction_strength * (tensor(sigmax(), sigmax()) + tensor(sigmay(), sigmay()))  # Interaction term
H = H0 + Hint  # Total Hamiltonian

# Define the initial state of the system
psi0 = tensor(basis(2, 0), basis(2, 1))  # Example initial state: |0⟩⨂|1⟩

# Simulate the time evolution of the system
result = mesolve(H, psi0, time_points, [], [])

# Extract the desired state from the result list
states = result.states

# Calculate the concurrence at each time point
concurrence = [concurrence(state) for state in states]

# Plot the concurrence as a function of time
import matplotlib.pyplot as plt

plt.plot(time_points, concurrence)
plt.xlabel('Time')
plt.ylabel('Concurrence')
plt.title('Effect of External Potential on Concurrence')
plt.show()