This is sort of a beginnery thing:
Transformers can only be designed for rational turns ratios. That is, you can't have sqrt(2) or pi turns ratios, only 1:2 or 57/64 and such. Often, you need to wind one for an irrational ratio: the most common case being impedance matching, where the turns ratio is sqrt(impedance ratio).
Suppose you need to match a 50 ohm transmission line to a pair of 50 ohm transmission lines wired in series: 100 ohms, as seen by the transformer. (This is called a 180 degree splitter or hybrid.) The impedance ratio is (100/50) = 2, so the voltage/turns ratio is sqrt(2) ~= 1.4142... RF transformers need to be wound with the smallest possible number of turns (because wire length limits the upper frequency range), so it would be nice to find the smallest number that gives an accurate ratio.
Well... an irrational number can't be expressed as a rational, but we can try and get close. Let's say the matching needs to be within 10% (which means the turns ratio has to be within 5%). How do we find a ratio? We can brute-force it by incrementing the numbers in (p/q) until the ratio gets close enough, but that's tedious (though, a good way for a computer program!).
Is there a better way? Certainly! We can find all* the best points, that we'd get with a brute-force method, using fewer steps in a smarter approach.
(*I don't think this is actually true, but there's a theorem about it that relates to this.)
Here's the procedure. Grab a standard (non-RPN) calculator and enter the desired number (to an adequate number of decimal places, or compute it first). If the number is < 1, take its reciprocal (hit 1/x). Then repeat:
1. Subtract the integral part (everything left of the decimal); write down this number.
2. 1/x
3. GOTO 1
You don't need to loop forever of course, but what you are doing is creating a continued fraction. Each number you subtract off, is another factor into the ratio you'll produce. And at each step of the way, you're getting more and more accurate. For 5% accuracy, you don't need more than about 1/sqrt(5%) steps, or thereabouts.
Or, if you happen to get an integral part that's rather large (like 5 or 10 or more), that means the previous step produced a pretty accurate subtraction, and you'll have a pretty good result stopping there. Because, when you're subtracting 5 from a remainder in the range of [0, 1) (average 0.5), then you have a 10% match, in that step alone -- which goes on top of the accuracy already achieved by the previous steps!
To compose the transformer ratio, simply reverse the process:
Enter the last integer
1/x
+ (2nd-last integer)
1/x
+ ...
...
1/x
+ (1st integer)
= Done!
If you follow this process through, on paper (or using an exact calculator), so you get the fraction (p/q) rather than its decimal value, you'll note that each integer alternates between multiplication and addition, and contributing to p or q. The result is that, as you spin off more integers, (p/q) gets closer to the original number.
Worked examples:
sqrt(2) for the original example. As it happens, the continued fraction expansion starts with 1 (because 1.414...) and goes on infinitely, producing 2 (doing this on a real computer will eventually discover rounding errors, but all irrationals actually have a repeating sequence in this form!). So we can pick ratios of:
1 + 1/(2) = 3/2 = 1.5
1 + 1/(2 + 1/(2)) = 7/5 = 1.4
1 + 1/(2 + 1/(2 + 1/(2))) = 17/12 = 1.41666...
and so on.
5:7 turns ratio isn't too bad, so we might settle for that. In a pinch, 2:3 isn't even too bad, giving a +12.5% impedance error.
Small ratios are also practical to build using transmission line transformer designs that don't have upper frequency limits. Large ratios get unwieldy though, especially with lots of prime factors, like 5, 7 and 17.
Example 2:
A vacuum tube amplifier might need an impedance ratio around 6600:8, or a turns ratio of 28.72... A ratio of 28:1 or 29:1 is pretty good, but the high impedance will end up needing quite a lot of turns (a few thousand), so we might as well calculate up to that point and see how accurate we can get!
28, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 2, 1, 56, ...
These give:
28
29
86/3
115/4
201/7
316/11
517/18
2384/83 (this is probably reasonable for a real transformer of this type)
2901/101
5285/184
(more is probably not practical; 5000 turns is a lot of winding!)
Example Fun:
What if we do pi? We can continue-fraction that quite easily, sure:
3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, ...
No, there's no pattern in this case: pi is transcendental. (Irrational (algebraic) numbers do have a repeating fraction.) You can see 7, 15 and 292 are pretty damn good steps (the next best is 84, a dozen or so steps later). These correspond to, guess which ratios? Let's write them out...
3 = 3/1 = 3
3 + 1/(7) = 22/7 = 3.142857...
3 + 1/(7 + 1/(15)) = 333/106 = 3.141509...
Which isn't bad already!
The famous ratio 355/113, high by only 85ppb, is produced by this series:
3 + 1/(7 + 1/(15 + 1/(1))) = 355/113 = 3.1415929...
The next better ratio takes many more digits:
3 + 1/(7 + 1/(15 + 1/(1 + 1/(292)))) = 103993/33102 = 3.1415926530... (-0.18ppb)
Tim