Inverting a function you cannot invert algebraically
Every calculator here is a pure function from inputs to a result. Goal seek asks the reverse question: what input produces this result? For most of these functions there is no closed-form inverse, so the answer is found numerically.
Bisection is the method used. Bracket the answer between a low and a high value known to straddle the target, evaluate the midpoint, discard whichever half cannot contain the answer, and repeat. Each iteration halves the interval, so the answer converges at a predictable rate regardless of how badly behaved the function is.
Why not Newton–Raphson
Newton's method converges far faster — quadratically rather than linearly — and it is the obvious choice for a smooth function. These functions are not smooth.
Almost every material calculator here contains a ceiling function, because you cannot buy part of a box. That makes the output piecewise constant: it steps rather than slopes. Newton's method needs a derivative, and the derivative of a step function is zero almost everywhere and undefined at the steps. It would divide by zero or shoot off to infinity.
Bisection needs no derivative. It needs only that the function moves in a consistent direction across the bracket, which these do. Slower convergence is a price worth paying for a method that cannot fail on the functions it is actually applied to.
Tolerance must be relative
The registry spans results from 0.02 cubic metres to 400,000 kilograms. An absolute tolerance that is sensible for one is meaningless for the other — four decimal places is absurd precision on a mass in tonnes and insufficient on a volume in cubic metres.
The solver therefore converges on relative tolerance, and so do the tests that check it. This was found the hard way: a test asserting an absolute tolerance failed at 17,657.998 against a target of 17,658, where the solver was entirely correct and the assertion was wrong.
The bracket is the hard part, not the iteration
Bisection's guarantee is conditional: it converges to a root if the function has OPPOSITE SIGNS at the two ends of the bracket. Supply a bracket where it does not, and there is nothing to converge to — the method has no way to start.
So the real work is finding two points that straddle the answer. The solver here expands outwards from a plausible starting range until it finds a sign change or gives up, and giving up is a legitimate outcome that has to be reported rather than papered over. A goal that is simply unreachable — a coverage no quantity of material achieves, a temperature the equation never reaches — produces no bracket, and the honest answer is that there is no solution rather than a number.
The opposite failure is quieter and worse. If the function changes sign TWICE inside the bracket, bisection still converges, and it converges to one of the roots without any indication that the other exists. On a physical problem the two roots are rarely equally meaningful: one is the answer and the other is a mathematical artefact at a negative depth, an impossible thickness or a flow in the wrong direction. This is why brackets are set from physical limits rather than from generous defaults, and why a solver's output is checked against the domain it was supposed to search.
Stepped functions may have no exact answer at all
The ceiling functions that rule out Newton's method have a second consequence that is easy to miss. A piecewise-constant output does not take every value: it jumps from one plateau to the next. If the requested target falls in the gap BETWEEN two plateaus, no input produces it, and no amount of iteration will.
Ask how much floor area twelve and a half boxes of tile covers and the honest answer is that no area does — twelve boxes cover one amount, thirteen cover another, and there is nothing between them. The solver's job in that case is to return the nearest achievable value, say which side of the target it falls on, and report the residual, rather than to return the midpoint of an interval it never actually reached.
This is also why the termination test matters more than it looks. Converging on the WIDTH of the bracket asks whether the input has been pinned down; converging on the residual asks whether the output is close enough. On a stepped function those two questions have different answers, and a solver that tests only the residual can iterate forever across a jump it can never land on. The guard is an iteration cap, which exists for this case rather than for slow convergence.
Floating point sets the other hard limit. A bracket cannot be halved below the spacing between adjacent representable numbers at that magnitude, so a tolerance tighter than the machine can express is a request to loop until the cap stops it. Relative tolerance largely avoids this, because it scales with the magnitude in the same way the representable spacing does.
The same problem outside this site
Goal seek here is a convenience over calculators that could in principle be inverted by hand. The technique matters far more where the forward equation itself cannot be rearranged, and several of those sit behind other papers on this site.
The friction factor in the general pipe-flow equation is the standard example: it appears on both sides of its own defining expression, so it is solved iteratively or read from a chart. Normal depth in an open channel is another — the depth appears in both the flow area and the wetted perimeter, and no rearrangement isolates it. Internal rate of return is a third, and it is a polynomial root rather than an algebraic subject.
In each case the profession has produced an explicit APPROXIMATION precisely to avoid iterating: a fitted formula that lands within a fraction of a per cent of the iterative answer across the range that matters. Those approximations are not inferior — for design purposes they are usually the right tool, because they are fast, deterministic, and cannot fail to converge. Iteration earns its place where no fitted form exists, or where the required accuracy is finer than the fit.
What a goal-seek answer is for
An inverted result is an intermediate rather than a deliverable. The answer to "what wall thickness gives this resistance" is a number with decimals, and insulation is sold in discrete thicknesses; the answer to "what span gives this deflection" is a number, and joists come in standard depths.
So the useful reading of a goal-seek result is which side of a catalogue value it falls on, not the digits themselves. Reporting it to more precision than the thing being specified can be bought in implies an accuracy the problem does not contain, which is why the results here are rounded to the resolution of the quantity rather than to the solver's tolerance.
It is also worth stating what inversion does NOT do to a calculator's assumptions. Running a model backwards does not make it more authoritative than running it forwards: every limitation on the forward page — the waste factor, the standard it follows, the conditions it assumes — applies unchanged to the inverted answer. A goal seek through an approximate model returns an approximate input, and it returns it with the same caveats, which is why the pages carry them either way round.
Basis
- Bisection method; guaranteed convergence for any continuous function with a sign change across the bracket.
- Brent, R.P. (1973), Algorithms for Minimization without Derivatives — the hybrid of bisection and faster methods used where a derivative exists and safety is still required.
- Colebrook-White and the Swamee-Jain explicit approximation to it, as an example of a fitted formula replacing an iteration.
- IEEE 754 double precision, for the representable spacing that sets the floor on any bracket-halving tolerance.
