title: solving ode with time-array input - PYTHON
body: <p>I am trying to solve this problem, searched stack overflow and couldn't find an answer.</p>
  
  <p>I want to integrate a set of state equations, where my inputs that I want to pass as arguments, are arrays as the same length of t.</p>
  
  <p>Example of time-invariant arguments:</p>
  
  <pre><code># state function
  def state(x, t, u_in):
      u     = x[0]
      v     = x[1]
      w     = x[2]
      phi   = x[3]
      theta = x[4]
      psi   = x[5]
      h     = x[6]
  
      ax   = u_in[0]
      ay   = u_in[1]
      az   = u_in[2]
      p    = u_in[3]
      q    = u_in[4]
      r    = u_in[5]
      pdot = u_in[6]
      qdot = u_in[7]
      rdot = u_in[8]
  
      xdot = np.zeros(len(x))
      xdot[0] = ax - g * np.sin(theta) + r * v - q * w
      xdot[1] = ay + g * np.sin(phi) * np.cos(theta) + p * w - r * u
      xdot[2] = az + g * np.cos(phi) * np.cos(theta) + q * u - p * v
      xdot[3] = p + (q * np.sin(phi) + r * np.cos(phi)) * np.tan(theta)
      xdot[4] = q * np.cos(phi) - r * np.sin(phi)
      xdot[5] = (q * np.sin(phi) + r * np.cos(phi)) / np.cos(theta)
      xdot[6] = u * np.sin(theta) - v * np.sin(phi) * np.cos(theta) - w * np.cos(phi) * np.cos(theta)
      return xdot
  
  
  # initial condition
  x0 = np.zeros(7)
  
  # set problem
  n = 101
  t = np.linspace(0, 10, num=n)
  uinp = np.zeros(9)
  uinp[0] = 0
  uinp[1] = 0
  uinp[2] = -g
  uinp[3] = 0
  uinp[4] = 0
  uinp[5] = 0
  uinp[6] = 0
  uinp[7] = 0
  uinp[8] = 0
  
  
  # solve ODE
  x = odeint(state, x0, t, args=(uinp,))
  </code></pre>
  
  <p>This works fine because my inputs are time invariant.</p>
  
  <p>What I want to do and it doesn't work is to set my uinp as np.zeros_like(t) and solve the same ODE.</p>
  
  <p>i.e.</p>
  
  <pre><code>uinp = np.zeros((n, 9))
  uinp[:, 0] = 0
  uinp[:, 1] = 0
  uinp[:, 2] = -g
  uinp[:, 3] = 0
  uinp[:, 4] = 0
  uinp[:, 5] = 0
  uinp[:, 6] = 0
  uinp[:, 7] = 0
  uinp[:, 8] = 0
  </code></pre>
  
  <p>and I get this error:</p>
  
  <pre><code>ValueError: setting an array element with a sequence.
  enter code here
  </code></pre>
  
  <p>Using a loop for each timepiece input is not an option, as it creates too much overhead and it takes forever to run this simulation.</p>
  
  <p>Thanks for the help and insights</p>