title: Using Python's sympy module to express a complicated function
body: <p>How can I symbolically express the following equation using python's sympy module, such that I could later find the second derivative and therefore compute the Hessian matrix? </p>
  
  <p>The Function</p>
  
  <p><a href="https://i.stack.imgur.com/oaUJB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oaUJB.png" alt="enter image description here"></a></p>
  
  <p>What I've tried: </p>
  
  <pre><code>import sympy
  Nc,Ns,Tc,Ysc,theta,theta_star,t,dt,sigma_s,measured,simulated=sympy.symbols(' Nc Ns Tc Ysc theta theta_star t dt sigma_s  measured simulated ')
  chi=(1/2*Nc*Ns) * sympy.mpmath.nsum(   1 / Tc *  sympy.integrate(  ((simulated - measured)  /  sigma_s )    **2) , (t,0,Tc))
  </code></pre>
  
  <p>The Error: </p>
  
  <pre><code>  File "C:\Anaconda1\lib\site-packages\sympy\concrete\expr_with_limits.py", line 358, in __new__
      "specify dummy variables for %s" % function)
  
  ValueError: specify dummy variables for (-measured + simulated)**2/sigma_s**2
  </code></pre>