The nonuniqueness of gravity or magnetic data inversion is well known. In order to remove ambiguity, some authors have sought solutions minimizing a functional describing geometrical or physical properties. Last and Kubik (1983), in particular, developed a method explaining the observed anomaly by structures of minimum volume. In this method the domain where anomalous sources are searched is divided into elementary prisms of a constant density or susceptibility contrast. Each elementary contrast is allowed to vary individually. Thus a contrast distribution is computed.The search for this kind of solution leads in general to geologically more appropriate bodies, but exceptions do occur. In this paper, the technique is broadened to include the search for solutions minimizing the moment of inertia with respect to the center of gravity or with respect to a given dip line passing through it. The resulting structures are both deeper and more compact, precisely as is required in specific cases. Theoretical and actual examples illustrate this flexible inversion technique.