In this paper we study particular linear and weakly linear systems of matrix equations over semirings, with the aim of describing and computing functions as solutions to those systems. Our special attention is devoted to solutions whose ranks are as small as possible. We prove the existence of solutions with the smallest ranks, give their characterizations, and present a method for their computations. Regarding weakly linear systems, the method is based on the well known partition refinement algorithm by Kanellakis and Smolka, adapted to work with weighted labeled transition systems. Moreover, we give a state reduction procedure of weighted automata based on a decomposition of solutions to particular linear and weakly linear systems.