Just watched a neat series of

videos on "mechanical computers" that were used to aim warship guns in realtime, using up to 25 input variables like speed, direction, enemy speed, wind, etc.

###
Adding

One simple example is adding using a differential, made clearer with two linear racks:

The position of the center gear is A + B / 2. You can see rack Ahas been moved to 4, which caused the gear center to move to 2, since rack B stayed still. If rack B moved to 4, too, the gear center would move another 2 units to 4 (4 + 4 / 2 = 4).

The same idea applies to a differential, where the racks are two bevel gears. Note that the middle gear spins freely on its shaft, and that the output is the rotation of that whole middle block as shown with the arrow. The outer two gears are locked to the outside shafts, but not the middle.

###
Inverse

To do things more complicated than adding or multiplying (which can all be done with gears), a cam and follower, or pin and slot are used. As the wheel rotates, it pushes the pin down at exactly a 1/x rate. By cutting the path in different ways, you can express just about any y = f(x) using this technique, as long as the slope isn't too step I imagine. Arbitrary functions using wheels and slots!

If you make the pin follow the curve cut on the surface of a cylinder, you can provide two inputs: z = f(x,y).

##
Integration

Hold on to your pants, you can even integrate with these chunks of metal. Imagine you want to know the total distance a ship has traveled, and your only input is the speed over time: s = f(t). On paper, you would need to calculate the area under the speed curve, or you could pull out one of these bad boys.

That bottom platter is rotating constantly, which rotates the balls above it through friction. The location of the balls can be shifted left and right. If the balls are positioned directly above the platter, they won't move since the speed is 0 in the center. At the edge of the platter, the speed is max. By adjusting the balls' position along with speed, you're effectively calculating the total distance (d = speed * time), or integrating the speed. It's basically just an adjustable gear ratio, but neat regardless.