title: How to optimize time-stepping algorithm in python?
body: <p>I have a piece of code which increments a time-step for the so-called <a href="http://en.wikipedia.org/wiki/Lorenz-95" rel="nofollow">Lorenz95 model</a> (invented by Ed Lorenz in 1995).  It's normally implemented as a 40-variable model, and displays chaotic behaviour.  I have coded up the time-stepping for the algorithm as follows:</p>
  
  <pre><code>class Lorenz:
      '''Lorenz-95 equation'''
  
      global F, dt, SIZE
      F = 8
      dt = 0.01
      SIZE = 40
  
      def __init__(self):
          self.x = [random.random() for i in range(SIZE)]
  
      def euler(self):
          '''Euler time stepping'''
          newvals = [0]*SIZE
          for i in range(SIZE-1):
              newvals[i] = self.x[i] + dt * (self.x[i-1] * (self.x[i+1] - self.x[i-2]) - self.x[i] + F)
          newvals[SIZE-1] = self.x[SIZE-1] + dt * (self.x[SIZE-2] * (self.x[0] - self.x[SIZE-3]) - self.x[SIZE-1] + F)
          self.x = newvals
  </code></pre>
  
  <p>This function euler is not slow, but unfortunately, my code needs to make a very large number of calls to it.  Is there a way I could code the time-stepping to make it run faster?</p>
  
  <p>Many thanks.</p>