Networks, and how a solve is checked

What a network answers, and how the answer is checked

A circuit has exactly one answer and a matrix finds it. The part that matters is not that the answer exists but that it can be checked twice, by routes that share no arithmetic — and that a circuit with no answer is refused by name rather than returned as a large plausible number.

A circuit made of resistors and sources has exactly one set of node potentials consistent with Kirchhoff’s two laws and with what each element does. Not approximately one, and not one that depends on the order the elements are considered in: the laws are linear, the element relations are linear, and a linear system with a non-singular matrix has a unique solution. That is the entire reason a circuit can be analysed at all, and it is worth stating plainly before anything is drawn, because everything else on this site is downstream of it.

A network solved, and checked: a bridge, which no series-parallel reduction reachesNode potentials from modified nodal analysis. The branch currents are then recomputed from each element's own law and summed at every node; the residual is 2.7e-16 of the largest current in the circuit, which is floating-point rounding and nothing else.a bridge, which no series-parallel reduction reachesnode a7.5566 Vnode b4.7993 Vcurrent law, rebuilt from the element laws2.71e-16 of the largest branch currentpower delivered against power dissipated4.33e-16 apart · 48.07 mWsolved, then checked — 6 elementsa linear network has no edge: this one is exact
Fig. 1 A five-resistor bridge, solved. No series-parallel reduction reaches this network — no two resistors in it are purely in series or purely in parallel — so the usual first method has nothing to grip. The matrix does not care. The numbers underneath are the check, and they are the subject of most of this essay.

The method, in one paragraph

Choose one node and call its potential zero. Every other node gets an unknown. At each of those nodes, write the statement that the currents leaving it sum to zero, expressing each current in terms of the potentials at its two ends: a resistor between nodes a and b carries (vavb)/R. That gives as many equations as unknowns, and solving them gives every potential in the circuit at once.

Two kinds of element do not fit that pattern, and the fix for both is the same. An ideal voltage source does not have a current determined by its terminal voltage — the voltage is fixed and the current is whatever the rest of the circuit demands — so the source’s current becomes an extra unknown, and its own constraint (that the two terminals differ by a stated amount) becomes an extra equation. An inductor is treated the same way, for a reason that turns out to matter enormously and is taken up below.

That is modified nodal analysis. It is not a clever method and it was not invented to be elegant; it was invented because it can be assembled by walking a list of elements and adding a fixed pattern of numbers into a matrix for each one, which is what makes it mechanical enough to trust.

Why the solve is complex-valued from its first line

The solver underneath this site works over the complex numbers everywhere, including for circuits containing nothing but resistors and batteries. That looks like an extravagance and it is the opposite of one.

A circuit’s behaviour at a frequency is found by replacing each capacitance by an admittance sC and each inductance by an impedance sL, where s is a complex number, and solving exactly the same equations. Direct current is s = 0. A sinusoidal steady state at frequency f is s = j2πf. A pole — a natural frequency at which the circuit can ring with nothing driving it — is a value of s at which the matrix stops being invertible. Three things that are usually taught as three subjects are one solve evaluated at three kinds of argument.

Building a real-valued solver and adding phasors afterwards is not an extension; it is a rewrite, in which every element’s contribution, every pivot and every residual changes type. Doing it over the complex numbers from the outset costs a few multiplications and buys the rest of the site.

There is a second consequence, less obvious and more useful. Because s enters the matrix linearly — every entry is a constant plus s times another constant — the determinant of the matrix is a polynomial in s. The poles of the circuit are the roots of that polynomial. Nothing anywhere on this site writes a transfer function down symbolically; the polynomial is recovered by sampling the determinant at a few dozen values of s and transforming, and its roots are found numerically. That is how the pole diagrams elsewhere in this collection are produced, and it is only available because the matrix was kept linear in s.

Keeping it linear in s is exactly why an inductor here carries a current unknown instead of an admittance of 1/(sL). The admittance form puts a pole at the origin inside the matrix, which makes direct current a special case needing separate treatment and turns the determinant into a ratio of polynomials rather than a polynomial. With the current unknown, zero frequency needs no special handling at all: the inductor’s own equation reads v = 0, which is precisely what a short circuit is.

The part that is actually hard

Assembling the matrix is the part most likely to be wrong and the part least likely to look wrong.

Consider what a mistake produces. A sign reversed in one element’s contribution, a pair of indices transposed, a controlled source referred to the wrong pair of nodes: none of these makes the matrix singular, none of them produces a warning, and none of them makes the resulting numbers implausible. What comes out is a smooth curve with sensible units and roughly the right shape, which is to say a figure that would pass any inspection a reader could perform.

This is not hypothetical. The response of a filter with one element mis-stamped still rolls off; the step response of a network with a reversed sign still settles. The error shows up as a factor somewhere, or as a corner in the wrong place, and there is nothing in the picture that says so.

So a picture is not the check. The check has to be arithmetic, and it has to be arithmetic that does not go through the thing being checked.

Two routes, and why they have to be genuinely two

Every solution returned by this site’s solver has passed two tests before any figure sees it.

The first is Kirchhoff’s current law, rebuilt. Once the node potentials are known, the current in each branch can be recomputed from that element’s own relation — a resistor’s from the potential difference and its resistance, a capacitor’s from the potential difference and sC, a source’s from the unknown that was solved for. Those currents are then summed at every node and required to be zero. Nothing in that recomputation uses the pattern of numbers that was stamped into the matrix, so a stamping error has nowhere to hide: the equations were solved consistently, but the solution does not satisfy the law it was supposed to encode.

On the bridge above, the largest branch current is a little over eight milliamperes and the worst node sum is about 2.7 × 10−16 of it. That is not a small error; it is no error, expressed in the only way a machine that rounds to sixteen digits can express one.

The second is deliberately not a restatement of the first. Current law constrains the currents and says nothing about whether the potentials that produced them are right, so a second test is needed that runs the other way. The power dissipated in the resistors is computed as |iR, which never reads a node potential. The power delivered by the sources is computed as the real part of v·i*, which never reads a resistance. Those two numbers agree only if the potentials and the currents are consistent with one another — which is exactly the thing the first test leaves open. On the bridge they agree to the same handful of final bits, on a dissipation of 48.07 milliwatts.

Neither test is expensive. Together they cost a few per cent of the solve, and they turn every figure on this site from a drawing that looks right into a drawing whose arithmetic has been audited by something other than a person looking at it.

A network solved, and checked: a three-section ladderNode potentials from modified nodal analysis. The branch currents are then recomputed from each element's own law and summed at every node; the residual is 1.4e-16 of the largest current in the circuit, which is floating-point rounding and nothing else.a three-section laddernode a3.8462 Vnode b1.5385 Vnode out0.7692 Vcurrent law, rebuilt from the element laws1.41e-16 of the largest branch currentpower delivered against power dissipated2.26e-16 apart · 61.54 mWsolved, then checked — 7 elementsa linear network has no edge: this one is exact
Fig. 2 A three-section ladder, where each section halves what reaches it. Every potential is a third of the one before, which is the kind of pattern that makes a network worth solving rather than measuring — and also the kind of pattern that would survive several plausible mistakes intact.

Controlled sources, which are why this generalises

A network of resistors and batteries would not need any of this machinery. What makes it worth building is that the same assembly handles elements whose behaviour depends on what is happening somewhere else in the circuit.

A transistor, to a first approximation, produces a current proportional to a voltage at another pair of terminals. An operational amplifier produces a voltage proportional to the difference between two others. A transformer relates a voltage at one winding to a voltage at another. All of these are controlled sources, and each stamps into the matrix in a fixed pattern exactly as a resistor does — the only difference is that the pattern touches four nodes instead of two, and is not symmetric.

That asymmetry is the whole content of the idea. A resistor’s contribution is symmetric because the relation between its two terminals is the same in both directions; an amplifier’s is not, because its input does not care what its output is doing. A matrix that is no longer symmetric is a circuit that has a direction, and every amplifier, every filter with gain and every feedback loop in this collection exists because of that.

A network solved, and checked: a network with a controlled source in itNode potentials from modified nodal analysis. The branch currents are then recomputed from each element's own law and summed at every node; the residual is 4.2e-16 of the largest current in the circuit, which is floating-point rounding and nothing else.a network with a controlled source in itnode b0.6803 Vnode c-34.0136 Vnode out-30.9215 Vcurrent law, rebuilt from the element laws4.21e-16 of the largest branch currentpower delivered against power dissipated5.27e-16 apart · 105.2 mWsolved, then checked — 6 elementsa linear network has no edge: this one is exact
Fig. 3 A network containing a controlled source of gain −50: the output is fifty times the potential at an internal node, inverted. The solved output is −30.92 volts for a one-volt input, which is not −50 — the difference is the loading of the source resistance and the output network, and it is solved rather than assumed away.

The number in that caption is worth pausing on. A reader given the gain of the controlled source would say the output is fifty times the input. It is not, because the input is divided down before it reaches the controlling node and the output is divided down again on the way out. Both divisions are consequences of the network rather than of the device, and the only way to get them right is to solve the whole thing at once. This is the first appearance on this site of a pattern that recurs in every field: the device’s specification is not the circuit’s answer, and the gap between them is computable.

A 9 V source with 500 mΩ inside itThe ideal source is the flat line. The solved terminal voltage leaves it at a rate set entirely by the internal resistance: 1% low at 180 mA, half gone at 9.0 A.024681010m100m110current drawn from the source (amperes)terminal voltage, solvedthe ideal source: 9 V at any current1% low at 180 mAthe model9 Vrloadsolved, then checked — the load swept over four decadesthe ideal source is 1% wrong above 180 mA
Fig. 4 The same solve put to the simplest possible question. A source with a resistance inside it, and the terminal voltage against the current taken from it: the flat line is what the ideal element in the netlist promises, and the curve is what the network containing it does. Every field on this site begins with a comparison of that shape.

Circuits that have no answer

A solver that always returns a number has not been tested, and a solver that returns a number for a circuit that has no answer is worse than one that fails.

Three things can go wrong, and all three are facts about the circuit rather than about the arithmetic.

A node with no conducting path to the reference. Its potential is not determined by anything. The matrix is singular, and the honest report is not “the matrix is singular” but “node x is floating”. This one has a frequency-dependent character that catches people: a capacitor conducts at any frequency above zero, so a node connected to the rest of the circuit only through capacitors has a perfectly good answer in an alternating-current sweep and no answer at all at direct current. The diagnosis has to know which question is being asked.

A loop of ideal voltage sources. Each source insists on the difference between its terminals; around a closed loop of them, Kirchhoff’s voltage law either says the same thing twice or says two contradictory things. Either way the currents circulating in the loop are not determined. This is decidable by walking the graph of voltage-source branches and asking whether any of them closes a cycle, which is cheaper and far more informative than waiting for the elimination to run out of pivot.

An element with no law of its own. A resistance of zero is not a resistor; it is a constraint between two nodes, and stamping it as an admittance of infinity is how a matrix acquires a row of nonsense. A perfect short circuit is expressed by merging the two nodes, not by an element.

Four networks the solver refusesEach has no answer, for a reason that is a fact about the circuit rather than about the arithmetic. The solver names the reason; it does not return a number.no path to grounda node whose potential nothing fixesrefused: floatingtwo sources in a loop5 V3 Vtheir currents are not determinedrefused: vloopa resistance of zero0 Ωan element with no law of its ownrefused: valuean output that is not a node?a response asked for where there is nothingrefused: nodesolved, then checked — each refusal was runa solver that never declines is untested
Fig. 5 Four networks with no answer, each refused by name. Every message shown was produced by running the case rather than by describing it — which is the difference between an assertion and a comment, since an assertion that no longer rejects has silently stopped testing anything.

The last of the four is a different kind of refusal and belongs here anyway: a response asked for at a node the network does not contain. It is a mistake made constantly while writing figures, it produces undefined in most systems and a plot of nothing in the rest, and naming it costs one line.

What is being refused, and what is merely inconvenient

There is a distinction worth drawing carefully, because the site leans on it repeatedly.

A network with a floating node has no answer. That is a statement about the mathematics and it is absolute: no amount of care, no better algorithm and no higher precision will produce one, because there is nothing there to produce.

A model asked to work outside its range is a different case. The circuit has an answer; the model does not describe it. An ideal operational amplifier asked what a gain of a hundred does at a megahertz will happily return a hundred, and the answer is not approximately right — the real device has no gain left there and the ideal one is describing a machine that does not exist. That, too, is refused on this site, and the refusals are just as deliberate. But the reason is different, and conflating the two would blur the thing the whole collection is about.

The first kind of refusal is in this file. The second kind is the rest of the site.

The schematic, and what it is worth

One decision about drawing follows directly from all of this and is worth stating early, because it governs every figure that follows.

Two schematics of the same circuit with different placement are the same circuit. The netlist is the content; the layout is a convenience for a human reader and carries no information whatever. That is in sharp contrast to a subject like mechanism design, where the geometry is the content and moving a pivot changes the machine.

The consequence is that a site organised around schematics is organised around the part that does not matter. Here, where a circuit needs showing, it is drawn small, in one consistent hand, and put in a corner of the canvas. What gets the space is the response: what the circuit does, plotted against whatever variable the argument turns on. That is also a considerably more honest use of a figure, because a response can be wrong in a way a reader can be told about, and a schematic essentially cannot.

A 10 kΩ + 10 kΩ divider, solved with its loadThe unloaded answer is 6.00 V. It is 1% low at a load of 495 kΩ and 4.00 V at a load equal to the divider's own resistance. The ratio does not predict any of this; the magnitude does.02461001k10k100k1M10Mload resistance across the output (ohms)output voltage, solved with the load in place6.0 V with nothing connected1% low at 495 kΩthe circuit12 VR₁R₂R_Lsolved, then checked — the load swept over six decadesthe ratio is 1% wrong below 495 kΩ
Fig. 6 The first response on this site, and the simplest network in it. Two equal resistors, and the output plotted against what is connected across it. The unloaded answer — the one the ratio predicts — is the flat line; everything below it is what the ratio does not know about.

What follows from having a solve

Once a network can be solved at any complex frequency and the answer checked, a surprising amount of the subject becomes one thing seen from different angles.

An impedance is what a network does when one ampere is forced into a pair of terminals: solve, and read the potential. A transfer function is what appears at one node when a source of one volt is applied at another: solve, and read the potential. A resonance is a frequency at which those readings become extreme. A pole is a value of s at which the matrix loses rank. A step response is the same network integrated forward in time, or equivalently the residues at those poles. A loop gain is the network cut at one point, driven on one side of the cut, and read on the other.

None of these needs its own machinery, and none of them is defined here by a formula. Every one is a question put to the same solve, which is why the figures in this collection can be trusted to agree with each other: they are not independent illustrations of a subject, they are readings of a single computation that has already been checked twice.

The rest of the collection is about what happens when the model handed to that solve stops describing the world — which it always eventually does, at a frequency, an amplitude or a size that can be computed.