build_matrix function

Build a state migration (transition) matrix