The problem, as the Traceback says, comes from the line x[i+1] = x[i] + ( t[i+1] – t[i] ) * f( x[i], t[i] ). Let’s replace it in its context:
x is an array equal to [x0 * n], so its length is 1
you’re iterating from 0 to n-2 (n doesn’t matter here), and i is the index. In the beginning, everything is ok (here there’s no beginning apparently… ๐ ), but as soon as i + 1 >= len(x) <=> i >= 0, the element x[i+1] doesn’t exist. Here, this element doesn’t exist since the beginning of the for loop.
To solve this, you must replace x[i+1] = x[i] + ( t[i+1] – t[i] ) * f( x[i], t[i] ) by x.append(x[i] + ( t[i+1] – t[i] ) * f( x[i], t[i] )).
The problem is with your line
x=np.array ([x0*n])
Here you define x as a single-item array of -200.0. You could do this:
x=np.array ([x0,]*n)
or this:
x=np.zeros((n,)) + x0
Note: your imports are quite confused. You import numpy modules three times in the header, and then later import pylab (that already contains all numpy modules). If you want to go easy, with one single
from pylab import *
line in the top you could use all the modules you need.