# Number of teeth in gears

I'm building something with an engine that uses gears to reduce/increse movement. The motor has itself some gears, and it's a stepper motor (it gives discrete steps), now the number of steps per revolution is not integer: $4075.77284...$, and I need to add gears to make it as close as possible to 720 steps, that is: each step must be as close as possible to $0.5º$.

So, this is the purely mathematical problem, the number of steps is given by:

$$n=64\frac{22\cdot 26\cdot 31\cdot 32}{9\cdot 9\cdot 10\cdot11}$$.

I'm going to use two wheels in series, so the problem is finding four integer numbers: $a,b,c,d$, such that:

$$n\frac{ab}{cd}\approx 720$$

Also, those four integers must be in the interval $(8,40)$.

The only thing I could think off was just trying, and found, by fixating $c=d=20$ and then setting $a=8,b=9$, that: $$n\frac{ab}{cd}=733.63911111111110585625$$

This gives a rotation of $0.4907044820099255577617$ degrees per step, with an error with respect to $0.5$ of $0.00929552$. That error is the important thing, and being around a hundredth of a degree per step, it's good enough for me, but I would like to know if there exists any analitical methods to get better solutions. Sadly, I don't have enough knowledge about diophantic equations to be able to do this on my own.

As a last resource, I would program something to test all possible combinations of $a,b,c,d$ in that interval, which is probably what I'm going to do, but if there's a more elegant solution, I'd love to know it.

Thanks anyone.

UPDATE: Ok, I programmed it, and found out that the best solution is: $a=8,b=31,c=36,d=39$, with an error of $0.0000436963449531591053$. Not a nice solution, I expected smaller numbers, but... good enough. Still, and analytical more general solution would be appreciated.

• Is there a typo in your expression for $n$? I get $(64\times22\times26\times31\times32)/(9\times9\times10\times11) \approx 4075.77284$, not $4075.3$. – Chris Culter Aug 5 '13 at 21:04
• No, the typo wsa in the 4075.3, thanks. – MyUserIsThis Aug 5 '13 at 21:04
• You may find this article interesting:ams.org/samplings/feature-column/fcarc-stern-brocot – awkward Aug 5 '13 at 21:47
• @awkward Thanks a lot. – MyUserIsThis Aug 5 '13 at 22:29
• Another constraint that you may want to impose is ensuring that the numbers of teeth on each pair of meshing gear are coprime. This is to avoid the so-called "hunting tooth" phenomenon that arises from wear, imperfect alignment, and non-identical tooth profiles. In engines this is quite important. – horchler Aug 5 '13 at 22:52

I don't think this can guarantee the optimal under constraints, but in general you can use the continued fraction representation to find best rational approximations to get something close. \begin{align} r &= \frac{720}{4075.7724\cdots} = 0.1766536\cdots \\ &= [0;5,1,1,1,18,3,\ldots] = \cfrac{1}{5+\cfrac{1}{1+\cfrac{1}{1+\cdots}}} \end{align} This gives the approximations $$r\simeq \frac{3}{17}, \quad \frac{56}{317}, \quad \frac{171}{968},\quad \frac{227}{1285}$$ which yield respectively $$0.500518\cdots, \quad 0.499992\cdots, \quad 0.500002\cdots, \quad 0.4999997\cdots$$ degrees per step. Unfortunately only the first factors into fractions that would fit your teeth constraints.
From here you can "hunt around" using the mediant of approximations that are above and below the target, as in the link @awkward gave in a comment. $$\frac{3}{17}\oplus\frac{56}{317}=\frac{59}{334} \\ \frac{3}{17}\oplus\frac{59}{334}=\frac{62}{351} =\frac{2\cdot 31}{3^3\cdot 13}\\ \frac{3}{17}\oplus\frac{227}{1285}=\frac{230}{1302}=\frac{5\cdot 23}{3\cdot 7 \cdot 31}$$
The second one gives your solution $(a,b,c,d)=(8,31,36,39)$, but I don't see a way to rule out finding something better other than exhaustively searching.
The third one gives the near miss $(a,b,c,d)=(10,23,31,42)$.
• I didn't know that about "best rational approximation", thanks. I will finally use $(10,13,23,32)$, because $39$ teeth was too much. And the error is still small. And I found these solutions by exhaustive search,not anything special. Thanks for the information, I will accept this answer. – MyUserIsThis Aug 6 '13 at 10:25