I am designing the classical Runge-Kutta scheme (RK4) for a large number of coupled equations in Python 2.7. Since there is going to be over a hundred coupled 1st order equations the for-loops will be hell large and I am looking for some optimization hints.
1. When calculating a vector of returned variables for RK coefficients is it better to...
- Prealocate a
numpy array
and fill it or - Use
list.append
for each variable andnumpy.array(list)
at the end?
2. The coupled equations obviously have coefficients. Is it better to...
- Insert them into the function called in RK4 steps (i.e. redefine them each time the function evaluation is called) or
- Label them as global variables?