title: graphing an equation with matplotlib
body: <p>I'm trying to make a function that will graph whatever formula I tell it to.</p>
  
  <pre><code>import numpy as np  
  import matplotlib.pyplot as plt  
  def graph(formula, x_range):  
      x = np.array(x_range)  
      y = formula  
      plt.plot(x, y)  
      plt.show()  
  </code></pre>
  
  <p>When I try to call it the following error happens, I believe it's trying to do the multiplication before it gets to <code>y = formula</code>. </p>
  
  <pre><code>graph(x**3+2*x-4, range(-10, 11))
  
  Traceback (most recent call last):  
    File "&lt;pyshell#23&gt;", line 1, in &lt;module&gt;  
      graph(x**3+2*x-4, range(-10, 11))  
  NameError: name 'x' is not defined  
  </code></pre>