I would be careful about the indexing of u
and y
when using nbefore
and nafter
so that I don’t get index out of bounds error.
Here is a Pythonic way –
ynew = [dt * u[i] + y[i] for i in xrange(1,n+1)]
unew = [dt * (k / m) * (y[i+1] + y[i-1]) for i in xrange(1,n+1)]
solved How I can convert this matlab code to python? [closed]