added main to compute M matrix