title: How to Fix "IndexError: invalid index to scalar variable" in Code
body: <pre><code>import numpy as np
  
  import matplotlib.pyplot as plt
  M = 1.0 # Mass of discus in kg
  g = 9.81 # Acceleration due to gravity (m/s^2)
  V = 30 # Initial velocity in m/s
  ang = 30 # Angle of initial velocity in degrees
  Cd = 0.54 # Drag coefficient
  Cl = 0.87
  dt = 0.01 # time step in s
  t = [0]
  vx = [V*np.cos(ang/180*np.pi)]
  vy = [V*np.sin(ang/180*np.pi)]
  x = [0]
  y = [1.8]
  rho = 1.2 #density in kg/m^3
  a_ref = 0.025 #area in m^2
  gamma = 35/180*np.pi
  
  
  drag=0.5 * rho * V**2 * a_ref * Cd
  lift = 0.5 * rho * V**2 * a_ref * Cl
  ax = ((rho*V**2*a_ref)/(2*M))*(-Cl *np.sin(gamma) - Cd * np.cos(gamma))
  ay = ((rho*V**2*a_ref)/(2*M))*(Cl* np.cos(gamma) - Cd* np.sin(gamma)) -g
  
  counter = 0
  
  while (y[counter] &gt;= 0):
      t.append(t[counter]+dt)
      vx.append(vx[counter]+dt*ax[counter])
      vy.append(vy[counter]+dt*ay[counter])
      x.append(x[counter]+dt*vx[counter])
      y.append(y[counter]+dt*vy[counter])
      vel = np.sqrt(vx[counter+1]**2 + vy[counter+1]**2)
      drag = 0.5 * rho * V**2 * a_ref * Cd
      lift = 0.5 * rho * V**2 * a_ref * Cl
      ax.append(((rho*V**2*a_ref)/(2*M))*(-Cl *np.sin(gamma) - Cd * np.cos(gamma)))
      ay.append(((rho*V**2*a_ref)/(2*M))*(Cl* np.cos(gamma) - Cd* np.sin(gamma)) -g)
      counter = counter +1
  
  plt.plot(x,y,'ro')
  plt.title(&quot;Womens Discus!&quot;)
  plt.ylabel(&quot;y (m)&quot;)
  plt.xlabel(&quot;x (m)&quot;)
  </code></pre>
  <p>I need to fix this error, in the line &quot;<code>vx.append(vx[counter]+dt*ax[counter])</code>&quot;, yet I'm a bit clueless as to how and have been staring at this problem for hours now. I was not allowed to attach my entire code (too long) so I just removed variables and some equations.</p>
  <p>Please let me know if I need to add anything in order to help solve this issue
  Any help would be greatly appreciated. TIA</p>