Matrix theory of electrical machinery