title: solving a Non- linear first order differential equation and getting a break in the plot
body: <p>I am trying to solve the elliptical differential equation using fourth-order runge-kutta method in python.</p>
  <p>After execution, I get a very small part of the actual plot that should be obtained and alongside with it an error saying that:</p>
  <pre class="lang-none prettyprint-override"><code>&quot;RuntimeWarning: invalid value encountered in double_scalars&quot;
  </code></pre>
  <pre class="lang-python prettyprint-override"><code>import numpy as np
  import matplotlib.pyplot as plt
  
  #Define constants
  g=9.8
  L=1.04
  
  #Define the differential Function
  def fun(y,x):
      return-(2*(g/L)*(np.cos(y)-np.cos(np.pi/6)))**(1/2)
  
  #Define variable arrays
  x=np.zeros(1000)
  y=np.zeros(1000)
  y[0]=np.pi/6
  dx=0.5
  
  #Runge-Kutta Method
  for i in range(len(y)-1):
      k1=fun(x[i],y[i])
      k2=fun(x[i]+dx/2, y[i]+dx*k1/2)
      k3=fun(x[i]+dx/2, y[i]+dx*k2/2)
      k4=fun(x[i]+dx, y[i]+dx*k3)
      
      
      y[i+1]=y[i]+dx/6*(k1+2*k2+2*k3+k4)
      x[i+1]=x[i]+dx
      
  #print(y)
  #print(x)
  plt.plot(x,y)
  plt.xlabel('Time')
  plt.ylabel('Theta')
  plt.grid()
  </code></pre>
  <p>And the graph I obtain is something like,
  <a href="https://i.stack.imgur.com/TwNCy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TwNCy.png" alt="theta vs. t graph" /></a></p>
  <p>My question is why am I getting the error message? Thanks for helping!</p>