factorized out the difference scheme generation and matrix generation