Resitor bank optmizer I have a real world problem where the math is beyond me.  I'm trying to set up an automated resistor bank much like a decade box.  I have $18$ channel that I can switch in up to four channels in parallel at a time.  Each channel is a fixed resistor value.  The system will take a target resistance and calculate which channels to turn on (up to four of the $18$) to get the closest resistance to the target.  That part is easy.  The part I need help with is picking the fixed resistor values for the $18$ channels.  I want to minimize the error between the target resistance and of the resistance value of the four channels switch in.  Here's what I have:
$R_t$ = target resistance
$R_1$ = $1$ of $18$ fixed values
$R_2$ = $1$ of $17$ fixed values  (one fix value used for $R_1$)
$R_3$ = $1$ of $16$ fixed values  (two fix values used for $R_1$ & $R_2$)
$R_4$ = $1$ of $15$ fixed values  (three fixed values used for $R_1$, $R_2$ & $R_3$)
Lets just take the case where we always switch in four channels so the error would be:
$$\left|\frac{1}{R_t} - (\frac{1}{R_1}+\frac{1}{R_2}+\frac{1}{R_3}+\frac{1}{R_4})\right|$$
Lets put some bounds on it.  The target resistance can be from $25$ to $300$  and any of the $18$ fixed resistor channels can be from $25$ to $10,000$
I was thinking the integral from $25$ to $300$ equals zero but I don't want the sum of the errors to be zero.  I want the largest error (for $25\to300$) to be the smallest it can be.  Plus I don't know how to deal with the problem that $R_1\to R_4$ can change to anyone of the $18$ fixed values at any time.  I don't know how to work the fixed values into the equation and solve for them.
 A: Fortunately, you measure the error by the reciprocal resistance, not the resistance itself. This allows us to simply work with reciprocals and their sums. Thus whet we are looking for, is $N=18$ numbers $a_1,\ldots,a_{18}$ such that the numbers that can be achieved as sums of up to four of these numbers are as uniformly dense as possible in a given range.
Without the four-summand limit, we'd simply let $a_k=2^{k-1}u$ for suitable $u$; then we can represent any multiple of $u$ form $0$ up to $(2^N-1)u$. We'll drop the $u$ for now and attempt to produce as many sonsecutive integers as possible,
For the given constraints, lets try what we can get by letting $a_k=A+(k-1)$, for example:
With one summand we can achieve $A,A+1,A+2,\ldots,A+n-1$. 
With two summands we can certainly achieve $2A+1,\ldots,2A+2n-3$. With three summands we get $3A+3,\ldots,3A+3n-6$. And with four summands $4A+6,\ldots,4A+3n-10$. So to cover a contiguous range of integers, we need $A$ to be an integer with 
$$ 2A+1\le A+n,\quad 3A+3\le 2A+2n-2,\quad 4A+6\le 3A+3n-5$$
or $A\le \min\{n-1, 2n-5, 3n-11\}$. So for $n=18$, we may choose $A=17$, and thus cover all integers from $17$ to $112$. Unfortunately, this method is very wasteful (because many of the ${18\choose 4}+{18\choose 3}+{18\choose 2}+{18\choose 1}=4047$ combinations produce the same total $R$), and with $\frac{112}{17}\approx 6.6 \ll 12=\frac{300\,\Omega}{25\,\Omega}$, we see that we managed to cover merely have the range we want.
One definitely needs better picks for the $a_k$ in order to be able to make use of more of the possible combinations. One has to get somewhat closer to the powers-of-two concept ... I suppose much of this process involves a good deal of trial and error.
A: I think I would use 
$$
a_k:=\operatorname{int}(25\cdot 400^{k/17})
$$
yielding the values
$$
\{25, 35, 50, 71, 102, 145, 207, 294, 419, 596, 848, 1206, 1716, 2442, 3473, 4941, 7029, 10000\}
$$
note that $400=10000/25$. This will allow you to match any given target resistance $R_t\in[25,300]$ with at least four significant bits of precision, since $300\times 2^4=4800<10000$. Choosing four resistances will be like choosing four non-zero decimal places in a base $2$ representation of $1/R_t$. Hence if this representation has many zeros, the precision will be higher.
A: You have 


*

*18 combinations for one resistor engaged

*$\frac{18 \times 17}{2}=153$ combinations for two resistors to be engaged

*$\frac{18\times 17\times 16}{3 \times 2}=816$ combinations for three resistors to be engaged

*$\frac {18 \times 17 \times 16 \times 15}{4 \times 3 \times 2}=3060$ combinations for four resistors to be engaged


So, 4047 options in total to choose from.
Question zero
Is this a large current application, would a 25 ohm resistor handle the current for instance, or are you going to need to spread it across the resistor bank for safety?
Question one
If this is an embedded programming exercise for the switching, do you have the facility to pre-determine all permissible combinations, save them to the hardware ranked in order of magnitude and perform a look-up at the time the switching is required?
Approximately 48kB of storage (value, resistor one location, resistor two location, resistor three location, resistor four location).
Question two
When you put several resistors in parallel, the total resistance is less than the smallest resistor, therefore to optimise your problem, you may desire fixed resistances which are comparatively large compared to your smallest target resistance.
Question three
Does the error tolerance have to be approximately the same for all target values, or is there scope for higher error at either end of the spectrum than the other?
Epilogue


*

*I do not think that mathematically, you will be able to solve this in a practical timescale, I would therefore suggest you generate a simulation using a programming language such as c,c++, python ...

*Without knowing more about your circumstances, this is as much as I can suggest at this time without jeopardising my integrity and your equipment.

