Resistor networks in R: the ResistorArray package
Robin K. S. Hankin
Abstract
This paper introduces the ResistorArray package of R routines, for analysis of resistor
networks. An earlier version of this vignette was published as Hankin (2006).
Keywords: Resistors, Resistor Arrays.
Many elementary physics courses show how resistors combine in series and parallel (Figure 1);
the equations are
Rseries = R1 + R2 (1)
1
Rparallel = (2)
R1 + R2−1
−1
However, these rules break down for many systems such as the Wheatstone bridge (Figure 2);
the reader who doubts this should attempt to apply equations 1 and 2 and find the resistance
between nodes 1 and 4 in the general case. This paper introduces ResistorArray, an R (R Core
Team 2012) package to determine resistances and other electrical properties of such networks.
R1 R2
R1
R2
Figure 1: Two resistors in series (top) and parallel (bottom)
Although this paper uses the language of electrical engineering, the problem considered is
clearly very general: many systems are composed of isolated nodes between which some
quantity flows and the steady states of such systems are generally of interest. Package Resis-
torArray has been applied to such diverse problems as the diffusion of nutrients among fungal
hyphae networks, the propagation of salinity between (moored) oceanographical buoys, and
hydraulic systems such as networks of sewage pumps. The general problem of determining
2 Resistor networks in R: the ResistorArray package
Node 2
R12 R24
Node 1 Node 4
R23
R13 R34
Node 3
Figure 2: The Wheatstone bridge
the resistance between two nodes of a resistor network requires matrix techniques. Consider
a network of n nodes, with node i connected to node j by a resistor of resistance Rij . Then
the network has a “conductance matrix” L with
(
−1/Rij if i 6= j
Lij = P (3)
k6=j 1/Rkj if i = j
Thus L is a symmetrical matrix, whose row sums and column sums are zero (and is therefore
singular). Then the analogue of Ohm’s law (viz V = IR) would be
Lv = i (4)
where v = (v1 , . . . , vn ) is a vector of potentials and i = (i1 , . . . , in ) is a vector of currents;
here ip is the current flow in to node p. Equation 4 is thus a restatement of the fact that
charge does not accumulate at any node. Each node of the circuit may either be fed a known
current1 and we have to calculate its potential; or it is maintained at a known potential and
we have to calculate the current flux into that node to maintain that potential. There are thus
n unknowns altogether. Thus some elements of v and i are known and some are unknown.
Without
loss of generality, we may partition these vectors into known and unknown parts:
0 0 0 k0
0
v = v ,vk u and i = i , i . Thus the known elements of v are vk = (v1 , . . . , vp )0 : these
0 u
would correspond to nodes that are maintained at a specified potential; the other elements
vu = (vp+1 , . . . , vn )0 correspond to nodes that are at an unknown potential that we have to
calculate. The current vector i may similarly be decomposed, but in a conjugate fashion;
thus elements iu = (i1 , . . . , ip )0 correspond to nodes that require a certain, unknown, current
to be fed into them to maintain potentials vk ; the other elements ik = (ip+1 , . . . , in )0 would
correspond to nodes that have a known current flowing into them and whose potential we
seek. Equation 4 may thus be expressed in terms of a suitably partitioned matrix equation:
vk iu
A B
= (5)
B0 C vu ik
1
This would include a zero current: in the case of the Wheatstone bridge of Figure 2, nodes 2 and 3 have
zero current flux so i2 and i3 are known and set to zero.
Robin K. S. Hankin 3
where, in R idiom, A=L[1:p,1:p], B=L[1:p,(p+1):n], and C=L[(p+1):n,(p+1):n].
Straightforward matrix algebra gives
vu = C−1 ik − B0 vk (6)
iu = A − BC−1 B0 vk + BC−1 ik
(7)
Equations 6 and 7 are implemented by circuit().
1. Package ResistorArray in use
Consider the Wheatstone Bridge, illustrated in Figure 2. Here the resistance between node 1
and node 4 is calculated; all resistances are 1 Ω except R34 , which is 2 Ω. This resistor array
may be viewed as a skeleton tetrahedron, with edge 1 missing. We may thus use function
tetrahedron() to generate the conductance matrix; this is
> L <- tetrahedron(c(1, 1, Inf, 1, 1, 2))
[,1] [,2] [,3] [,4]
[1,] 2 -1 -1.0 0.0
[2,] -1 3 -1.0 -1.0
[3,] -1 -1 2.5 -0.5
[4,] 0 -1 -0.5 1.5
Observe that L[1,4]==L[4,1]==0, as required. The resistance may be determined by function
circuit(); there are several equivalent methods. Here node 1 is earthed—by setting it to
zero volts—and the others are given a floating potential; viz v=c(0,NA,NA,NA). Then one
amp is fed in to node 4, zero amps to nodes 2 and 3, and node 1 an unknown current, to be
determined; viz currents=c(NA,0,0,1). The node 1-to-node 4 resistance will then be given
by the potential at node 4:
> circuit(L,v=c(0, NA, NA, NA),currents=c(NA, 0, 0, 1))
$potentials
[1] 0.0000000 0.5454545 0.4545455 1.1818182
$currents
[1] -1 0 0 1
Thus the resistance is about 1.181818 Ω, comparing well with the theoretical value of 117/99 Ω.
Note that the system correctly returns the net current required to maintain node 1 at 0 V as
−1 A (which is clear from conservation of charge). The potential difference between nodes 2
and 3 indicates a nonzero current flow along R23 ; currents through each resistor are returned
by function circuit() if argument [Link] is set to TRUE. Package ResistorArray
solves a problem that is frequently encountered in electrical engineering: determining the
electrical properties of resistor networks. The techniques presented here are applicable to
4 Resistor networks in R: the ResistorArray package
many systems composed of isolated nodes between which some quantity flows; the steady
states of such systems generally have an electrical analogue. This paper explicitly presents
a vectorized solution method that uses standard numerical techniques, and discusses the
corresponding R idiom.
References
Hankin RKS (2006). “Resistor networks in R: Introducing the ResistorArray package.” R
News, 6(2), 52–54.
R Core Team (2012). R: A Language and Environment for Statistical Computing. R Foun-
dation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http:
//[Link]/.
Affiliation:
Robin K. S. Hankin
Auckland University of Technology
2-14 Wakefield Street
Auckland
New Zealand
E-mail: [Link]@[Link]