Write a MATLAB function [speed] = planetary (N, emesh, first, last, arm) that computes the speed of a given link in a single-stage planetary gear train. N is a vector containing the numbers of gear teeth in the ordinary gear train from the first gear (a sun or ring) to the last gear (a sun or ring), excluding simple idlers. The parameter emesh is the number of mesh points in this ordinary train where both gears have external gear teeth (including any idlers). The arguments first, last, and arm are the speeds of the first gear, the last gear, and the carrier arm, respectively. The planetary function computes the speed of whichever link speed is initially specified as 'output'.

Note that this function will be used to find any speed ratio of interest by specifying the speed of the fixed gear as 0 rpm and the speed of the input as 1 rpm. Then, the output speed is numerically equal to the speed ratio e_oi= output speed / input speed. Also, the speed of a planet can be found by selecting it as the output gear and only specifying the tooth numbers in the ordinary train from the input gear to the planet.