title: Solve a ODE for arrays of parameters (Python)
body: <p>*I am aware that this question is quite simple but I would like to know the best way to set up such a for loop in Python. </p>
  
  <p>I have written a program already to calculate and plot the solution to a 2nd order differential equation (this code is given below). </p>
  
  <p>I would like to know best methods for repeating this calculation for an array of f parameters (hence <code>f_array</code>). I.e. so that the plot shows <code>20</code> sets of data referring to solutions as a function of <code>t</code> each with a different value of <code>f</code>.</p>
  
  <p>Cheers for any ideas.</p>
  
  <pre><code>from pylab import *
  from scipy.integrate import odeint
  
  #Arrays.
  tmax = 100
  t = linspace(0, tmax, 4000)
  fmax = 100
  f_array = linspace(0.0, fmax, 20)
  
  #Parameters
  l = 2.5
  w0 = 0.75
  f = 5.0
  gamma = w0 + 0.05
  m = 1.0
  alpha = 0.15
  beta = 2.5
  
  def rhs(c,t):
      c0dot = c[1]
      c1dot = -2*l*c[1] - w0*w0*c[0] + (f/m)*cos((gamma)*t)-alpha*c[0] - beta*c[0]*c[0]*c[0]
      return [c0dot, c1dot]
  
  init_x = 15.0
  init_v = 0.0
  init_cond = [init_x,init_v]
  ces = odeint(rhs, init_cond, t)
  
  s_no = 1
  subplot(s_no,1,1)
  xlabel("Time, t")
  ylabel("Position, x")
  grid('on')
  plot(t,ces[:,0],'-b')
  title("Position x vs. time t for a Duffing oscillator.")
  show()
  </code></pre>
  
  <p>Here is a plot showing the solution to this equation regarding a single value of <code>f</code> for an array of <code>t</code> values. I would like a quick way to repeat this plot for an array of <code>f</code> values.</p>
  
  <p><img src="https://i.stack.imgur.com/evGl5.png" alt="http://i61.tinypic.com/28bgyzs.png"></p>