MATLAB code for magnetics inversion