def main(): n_vertices = 10 edges = cg.cycle_graph(n_vertices) laplacian = gl.get_laplacian(edges,n_vertices,isDirected = False) print("Laplacian Matrix: \n",laplacian) eigenVals = np.linalg.eigvals(laplacian) eigenVals = np.sort(eigenVals) print("Two smallest eigen values are = ",eigenVals[:2]) print("Two largest eigen values are = ",eigenVals[::-1][:2])
# initialize x x = np.zeros((len(x_0), len(time_arr))) x[:, 0] = x_0 # copy x_0 to 1st col of x for i in range(0, len(time_arr) - 1): x[:, i + 1] = (-1) * (np.matmul(L, x[:, i])) * dt + x[:, i] for j in range(0, len(x_0)): plt.plot(time_arr, x[j, :]) plt.show() if __name__ == '__main__': x_0 = [20, 10, 15, 12, 30, 12, 15, 16, 25] # initial conditions T = 20 # simulation time # Define graph # E = [[0,2],[1,2],[3,2],[2,4],[2,6],[5,4],[7,4],[4,6],[5,6],[7,6],[8,6]] # for Exercise 5 - 2 E = [[0, 2], [1, 2], [3, 2], [2, 6], [5, 4], [7, 4], [4, 6], [5, 6], [8, 6]] # for Exercise 5 - 3 # E = [[0,2],[1,2],[3,2],[2,4],[2,6],[5,4],[7,4],[4,6],[7,6],[8,6],[1,3],[2,8],] # for Exercise 5 - 4 # E = [[0,2],[1,2],[3,2],[2,4],[5,4],[7,6],[8,6]] # for Exercise 5 - 5 n_vertices = 9 laplacian = gl.get_laplacian(E, n_vertices, isDirected=False) eigenVals = np.linalg.eigvals(laplacian) print("Eigen values are: ", np.sort(eigenVals)) simulate_consensus(x_0, T, laplacian, dt=0.001)
x[:, 0] = x_0 # copy x_0 to 1st col of x for i in range(0, len(time_arr) - 1): x[:, i + 1] = (-1) * (np.matmul(L, x[:, i])) * dt + x[:, i] for j in range(0, len(x_0)): plt.plot(time_arr, x[j, :]) plt.ylabel('Robot(s) Reading') plt.xlabel('Time') plt.show() if __name__ == '__main__': x_0 = [20, 10, 15, 12, 30, 12, 15] # initial conditions T = 20 # simulation time # Define graph # E = [[0,2],[1,4],[2,1],[2,3],[2,5],[4,5],[6,3]] # for Figure 3(a) # E = [[0,2],[1,4],[2,1],[2,3],[3,6],[5,2],[5,4]] # for Figure 3(b) # E = [[1,4],[2,5],[4,5],[6,3]] # for Figure 4(a) # E = [[2,1],[5,4],[3,6]] # for Figure 4(b) E = [[0, 2], [2, 3], [5, 2]] # for Figure 4(c) n_vertices = 7 laplacian = gl.get_laplacian(E, n_vertices, isDirected=True) eigenVals = np.linalg.eigvals(laplacian) print("Eigen values are: ", np.sort(eigenVals)) simulate_consensus(x_0, T, laplacian, dt=0.001)
if __name__ == '__main__': x_0 = [20, 10, 15, 12, 30, 12, 15] # initial conditions T = 300 # simulation time switch_time = 2 # Define graph # E1 = [[0,2],[1,2],[1,4],[2,0],[2,1],[2,3],[2,5],[3,2],[3,6],[4,1],[4,5],[5,2],[5,4],[6,3]] # for Figure 2(a) # E2 = [[0,2],[1,2],[1,4],[2,0],[2,1],[2,3],[3,2],[3,6],[4,1],[4,5],[5,4],[6,3]] # for Figure 2(b) # E3 = [[0,2],[1,2],[2,0],[2,1],[2,3],[2,5],[3,2],[3,6],[4,5],[5,2],[5,4],[6,3]] # for Figure 2(c) # E = [E1,E2,E3] # E1 = [[0,2],[1,4],[2,1],[2,3],[2,5],[4,5],[6,3]] # for Figure 3(a) # E2 = [[0,2],[1,4],[2,1],[2,3],[3,6],[5,2],[5,4]] # for Figure 3(b) # E = [E1,E2] E1 = [[1, 4], [2, 5], [4, 5], [6, 3]] # for Figure 4(a) E2 = [[2, 1], [5, 4], [3, 6]] # for Figure 4(b) E3 = [[0, 2], [2, 3], [5, 2]] # for Figure 4(c) E = [E1, E2, E3] laplacian_list = [] n_vertices = 7 for i in range(0, len(E)): laplacian_list.append( gl.get_laplacian(E[i], n_vertices, isDirected=True)) simulate_consensus_switch(x_0, T, laplacian_list, switch_time, dt=0.001)