Maxwell's equations for longitudinally inhomogeneous (irregular) waveguides with impedance walls are equivalently reduced to an infinite set of ordinary differential equations (ODE) by applying transverse expansions. The resulting set of ODE is used for analysis of gyrotron cavities. In particular, the effects of mode conversion and ohmic losses on the operational frequency, quality factor, and field distribution in gyrotron cavities operating in the sub-millimeter range are investigated.