Support non-square matrices

Use ginv (MASS) instead of solve to support non-square matrices.