A solution of some inverse problems in geomagnetism and gravimetry