基于节点的电阻器数量

Number of resistors based on nodes

我有一个 3x3 网络。是否有数学关系可以根据节点数告诉我电阻器的数量?

比如我这里有9个节点,12个电阻。比如说 16 (4x4)、25 (5x5)、36 (6x6) 个节点需要多少个电阻?

假设总是正方形网格,节点数等于网格大小的平方。

nodes = grid_size ** 2

电阻数量遵循这个规律:

resistors = 2 * grid_size * (grid_size - 1)

完整代码:

grid_size = int(input("Please input grid size (e.g. 3x3 should be entered as 3):"))
nodes = grid_size**2
resistors = 2 * grid_size * (grid_size - 1)
print(f'Nodes: {nodes}\nResistors: {resistors}')