title: Cannot differentiate wrt a complicated variable in Sympy
body: <p>(I understand the title makes this sound like a duplicate question to <a href="https://stackoverflow.com/questions/13351288/sympy-cant-differentiate-wrt-the-variable">Sympy Can&#39;t differentiate wrt the variable</a>, but I'm fairly certain it is quite different. I apologize in advance if I am mistaken)</p>
  
  <p>I'm trying to solve the Double Pendulum using Hamiltonian Mechanics, but Sympy is having trouble taking one of the derivatives. The code is below, but it's much easier to read the <a href="http://nbviewer.ipython.org/github/pixatlazaki/iPython_Notebooks/blob/master/Double_Pendulum.ipynb" rel="nofollow noreferrer">iPython Notebook over at nbviewer.ipython.org</a></p>
  
  <pre><code>from __future__ import division
  from sympy import *
  init_session()
  r_1,r_2,l_1,l_2, m_1, m_2, rdot_1, rdot_2,g = symbols("r_1 r_2 l_1 l_2 m_1 m_2 \dot{r_1} \dot{r_2} g")
  phi_1, phi_2 = symbols("phi_1 phi_2", cls=Function)
  phi_1 = phi_1(t)
  phi_2 = phi_2(t)
  
  r_1 = Matrix([l_1 * sin(phi_1), -l_1 * cos(phi_1)])
  rdot_1 = r_1.diff(t)
  r_2 = Matrix([r_1[0] + l_2 * sin(phi_2), r_1[1] -l_2 * cos(phi_2)])
  rdot_2 = r_2.diff(t)
  
  T = (1/2) * m_1 * rdot_1.T * rdot_1 + (1/2) * m_2 * rdot_2.T * rdot_2
  T = T[0]
  
  U = -g * ((m_1 * r_1[1]) + (m_2 * r_2[1]))
  
  L = symbols("\mathcal{L}")
  L = T - U
  
  H = symbols("\mathcal{H}")
  H = T + U
  
  p_1, p_2 = symbols("p_1 p_2")
  p_1 = L.diff(phi_1.diff(t))
  p_2 = L.diff(phi_2.diff(t))
  
  eq1_1 = p_1.diff(t) + H.diff(phi_1)
  eq1_2 = p_2.diff(t) + H.diff(phi_2)
  eq2_1 = phi_1.diff(t) - H.diff(p_1)
  </code></pre>
  
  <p>The last line yields the following error:</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-96-83bfafadd08f&gt; in &lt;module&gt;()
  ----&gt; 1 eq2_1 = phi_1.diff(t) - H.diff(p_1)
        2 eq2_2 = phi_2.diff(t) - H.diff(p_2)
  
  /Library/Python/2.7/site-packages/sympy/core/expr.pyc in diff(self, *symbols, **assumptions)
     2773         new_symbols = list(map(sympify, symbols))  # e.g. x, 2, y, z
     2774         assumptions.setdefault("evaluate", True)
  -&gt; 2775         return Derivative(self, *new_symbols, **assumptions)
     2776 
     2777     ###########################################################################
  
  /Library/Python/2.7/site-packages/sympy/core/function.pyc in __new__(cls, expr, *variables, **assumptions)
     1027                 from sympy.utilities.misc import filldedent
     1028                 raise ValueError(filldedent('''
  -&gt; 1029                 Can\'t differentiate wrt the variable: %s, %s''' % (v, count)))
     1030 
     1031             if all_zero and not count == 0:
  ValueError: 
  Can't differentiate wrt the variable:
  1.0*l_1*(l_1*m_1*Derivative(phi_1(t), t) +
  l_1*m_2*Derivative(phi_1(t), t) + l_2*m_2*cos(phi_1(t) -
  phi_2(t))*Derivative(phi_2(t), t)), 1
  </code></pre>
  
  <p>Is the expression too complicated? Or am I misunderstanding how to use diff()? </p>