Multi-level least squares method (Matlab program)