import numpy as np import matplotlib.pyplot as plt import scipy.sparse as ssp import scipy.sparse.linalg as sla n = 1000 # number of timesteps T = 20 # time will vary from 0 to T with step delt ts = np.linspace(0,T,n+1) delt = T/n gamma = .05 # damping, 0 is no damping A = np.zeros((4,4)) B = np.zeros((4,2)) A[0,0] = 1 A[1,1] = 1 A[0,2] = (1-gamma*delt/2)*delt A[1,3] = (1-gamma*delt/2)*delt A[2,2] = 1 - gamma*delt A[3,3] = 1 - gamma*delt B[0,0] = delt**2/2 B[1,1] = delt**2/2 B[2,0] = delt B[3,1] = delt K = 6 # 6 drones np.random.seed(1) p_0 = np.random.randn(2,K)*2 # initial positions v_0 = np.random.randn(2,K) # initial velocities print("Initial position:\n", p_0) print("Initial velocity:\n", v_0) plt.figure(figsize=(14,9), dpi=100) for i in range(K): plt.plot(p_0[0,i], p_0[1,i], 'ro', markersize=5) plt.arrow(p_0[0,i], p_0[1,i], v_0[0,i], v_0[1,i], head_width=0.2, width=0.05, ec='none') plt.title('Initial position and velocity') plt.axis('equal') plt.xlabel(r'$x$ position') plt.ylabel(r'$y$ position') plt.xlim(-10,20) plt.ylim(-5,15) plt.grid() plt.show() r_formation = 1 # the radius of the formation circle v_formation = 2 # the speed difference between the leader and the followers # your code here