# ResistorWebCalculator **Repository Path**: Louis-Liu-one/ResistorWebCalculator ## Basic Information - **Project Name**: ResistorWebCalculator - **Description**: 一种利用图论计算任意有限电阻网的等效电阻的一般方法。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-15 - **Last Updated**: 2025-11-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 利用图论计算任意有限电阻网的等效电阻 调用`resistor_web_calculator`模块以计算电阻网各处电流,再计算电阻网总电流以得出等效电阻。Demo如下: ```python from gaussian_eqsolver import * from resistor_web_calculator import * # 求 a, d 之间的电阻,电流方向 a -> d nodea, noded = WireNode(), WireNode() nodeb, nodec = WireNode(), WireNode() # 导线结点 r1 = Resistor(2., nodea, nodeb) # a -> b 2Ω r2 = Resistor(1., nodea, nodec) # a -> c 1Ω r3 = Resistor(1., nodeb, noded) # b -> d 1Ω r4 = Resistor(2., nodec, noded) # c -> d 2Ω r5 = Resistor(1., nodeb, nodec) # b -> c 1Ω unknown_count = 5 # 5 个电阻 -> 5 个未知数 voltage = 7. web = ResistorWeb( [r1, r2, r3, r4, r5], # 所有电阻 {nodeb, nodec}, # 除源汇点外所有导线结点 nodea, noded, # 源点、汇点 voltage, # 源汇点间电压 ) solution = web.get_equations().solve() # 电阻网各处电流 current = sum( # 电路中总电流,是电流汇点 d 连接的所有电阻的电流之和 [resistor.current for resistor in noded.in_resistors], start=Equation([0] * unknown_count)).evaluate(solution) print('Test Case 1:') print('Total Voltage: ', voltage, 'V', sep='') print('Total Current: ', current, 'A', sep='') print('Equivalent Resistance: ', voltage / current, 'Ω', sep='') ``` 输出 ``` Test Case 1: Total Voltage: 7.0V Total Current: 5.0A Equivalent Resistance: 1.4Ω ``` Test Case 2, 3 可以在`calculator_test.py`中获取。若想了解具体原理,请阅读`pdf/main.pdf`。 ## 文件组织 - **gaussian_eqsolver.py**:Gaussian消去法求解线性方程组; - **resistor_web_calculator.py**:求解电阻网等效电阻模块; - **calculator_test.py**:对求解模块的若干测试,可以在这里获取demos; - **pdf/main.pdf**:记录了笔者对于求解方法的发现、优化、实现的过程。