The method of matrix calculations is widely applied in the theory of electron- and ion-optics, especially in the aberration theory. In the present paper, a rotationally symmetrical electron-optical system and an ion-optical system with crossed toroidal electric and inhomogeneous magnetic fields are treated respestively. The general transfer matrices for the above mentioned electron- and ion-optical systems possessing the primary aberrations are derived. As a direct consequence of Liouville's theorem, we prove that the determinant of the transfer matrix has the value 1 in the approximation up to the primary aberrations. This general conclusion is useful for the electron-and ion-optical a berration theory and the computer-aided design.