I'm running a code that is based on a while loop to similate a chemical process. It simulates an added amount of species each second, and the mass transport, reaction, pressure, energy production etcetera that is coupled with it. When the material limit is reached, the addition stops and the system runs a little longer until nearly everything has reacted away. The problem is, there is a complicated equation involved using vpasolve, and simulating every second is starting to take very long times (over 1500 seconds for 15000 iterations). A larger timestep is not really an option due to required accuracy.
I would like to pre-allocate memory by defining some of the results in arrays already, since I've read that this can reduce computational speed. However, beforehand, I don't know for how many iterations my system will run, therefore I don't know how big my arrays should be. Would it already help to make "zeros" arrays that are plenty large for sure? And how could I deal with this when plotting my results?
Thanks in advance!