The Maxwell equations for longitudinally inhomogeneous (irregular) waveguides with impedance walls are reduced equivalently to a system of ordinary differential equations by applying transverse expan sions. The obtained system of equations for amplitudes of the coupled modes is used to analyze gyrotron cav ities. Specifically, the effect of mode conversion and ohmic losses on the eigenfrequencies, quality factors, and field distributions in the gyrotron cavities operating in the submillimeter range is investigated.