Using matrices instead of advancing simulation step by step