I have a problem in physics formulated via an ODE. Now I like to solve it numerically using Pythons scipy.integrate and the therein complex_ode. I figured out how and it works but now I like to optimize my code and I ran into a question:
I need a massive amount of grid points so that the solution converges. So I tried setting another integrator method with stepsize control (dop853). I am not really familiar with that feature but it works as well and is much faster than my approach. Here's a simple MWE which does not reflect my complicated ODE but the structure of the setup (complex valued etc.) is the same:
from scipy import * from scipy.integrate import * from pylab import * grid = linspace(0, 8, 10e3) dgrid = (grid-grid)*ones(100e3) def RHS(t, x): return -x y = zeros(len(grid), dtype=complex) y = 1.0 solver = complex_ode(RHS) solver.set_initial_value(y, grid).set_integrator('dop853') for t in range(len(grid)): solver.integrate(solver.t+dgrid[t]) y[t] = solver.y plot(grid, y.real) show()
But now the question: I now of course want to relate the time grid to the solution. What grid is now connected to the solution? Is it still the grid I was introducing (grid) or does the stepsize control calculate at different time steps and I would need another time array?