MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / wheatstone_solver

Function wheatstone_solver

electronics/wheatstone_bridge.py:5–35  ·  view source on GitHub ↗

This function can calculate the unknown resistance in an wheatstone network, given that the three other resistances in the network are known. The formula to calculate the same is: --------------- |Rx=(R2/R1)*R3| --------------- Usage examples: >>> wheatstone_solver

(
    resistance_1: float, resistance_2: float, resistance_3: float
)

Source from the content-addressed store, hash-verified

3
4
5def wheatstone_solver(
6 resistance_1: float, resistance_2: float, resistance_3: float
7) -> float:
8 """
9 This function can calculate the unknown resistance in an wheatstone network,
10 given that the three other resistances in the network are known.
11 The formula to calculate the same is:
12
13 ---------------
14 |Rx=(R2/R1)*R3|
15 ---------------
16
17 Usage examples:
18 >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5)
19 10.0
20 >>> wheatstone_solver(resistance_1=356, resistance_2=234, resistance_3=976)
21 641.5280898876405
22 >>> wheatstone_solver(resistance_1=2, resistance_2=-1, resistance_3=2)
23 Traceback (most recent call last):
24 ...
25 ValueError: All resistance values must be positive
26 >>> wheatstone_solver(resistance_1=0, resistance_2=0, resistance_3=2)
27 Traceback (most recent call last):
28 ...
29 ValueError: All resistance values must be positive
30 """
31
32 if resistance_1 <= 0 or resistance_2 <= 0 or resistance_3 <= 0:
33 raise ValueError("All resistance values must be positive")
34 else:
35 return float((resistance_2 / resistance_1) * resistance_3)
36
37
38if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected