Generated the matrix dynamically