title: Lagrange interpolation in Python: as a result matematical formula
body: <p>I'm trying to use Lagrange interpolation for few points. As a result I need matematical formula, for example:</p>
  
  <pre><code>Lx=[1,2,3],
  Ly=[1,4,9],
  result = x^2 
  </code></pre>
  
  <p>Instead of this I get <code>"-4.0*X*(-0.5*X - 1.0)*(-0.2*X + 0.2)*(-0.142857142857143*X +..."</code></p>
  
  <p>When I put for example 5 in place of X (line 12) i get "25", correct answer. 
  Can anybody help me?   </p>
  
  <pre><code>import sympy 
  def Lagrange (Lx, Ly):
      X=sympy.symbols('X')
      if  len(Lx)!= len(Ly):
          print "ERROR"
          return 1
      y=float(0.0)
      for k in range ( len(Lx) ):
          t=float(1.0)
          for j in range ( len(Lx) ):
              if j != k:
                  t=t* ( (X-Lx[j]) / float(Lx[k]-Lx[j]) ) # when I put number, OK
          y+= t*Ly[k]
      return y
  
  Lx=[-4,-2,0,1,3]
  Ly=[16,4,0,1,9]
  print Lagrange(Lx,Ly)
  </code></pre>