What exactly is the issue you are having? Recent versions of SymPy
allow you to take derivatives with respect to functions, so something
like

theta = Function('theta')
expr = theta(t).diff(t)**2 + cos(theta)
expr.diff(theta(t))
expr.diff(theta(t).diff(t))

should work.

By the way, you'll want to look at the mechanics module if you are
using SymPy to do mechanics. A lot of this has already been written
up, and also there are classes for "mechanics symbols" which are
functions of t, but which print nicer.

Aaron Meurer

On Tue, Oct 15, 2013 at 12:46 PM, Cavendish McKay
<[email protected]> wrote:
> Hello,
>
> I'm a relatively new sympy user, and am experiencing some confusion
> regarding the distinction between symbols and functions, especially in
> situations where I want to take derivatives.  Some context:  Let's say I'm
> trying to get the equations of motion for a system from its Lagrangian.  As
> a simple example, consider the Lagrangian for the simple pendulum $$L = 1/2
> m l^2 \dot\theta^2 - mg(1-\cos\theta)$$, where the dot represents a time
> derivative.  The equation of motion is given by $$ {\partial \over \partial
> t}\left({\partial L \over \partial \dot\theta}\right) - {\partial L \over
> \partial\theta} = 0. $$
>
> Now, my problem. If I declare theta as a symbol, when I try to differentiate
> with respect to time, I get zero (which makes sense, I guess; it doesn't
> have explicit time dependence). If, however, I declare it as a function, I
> run into trouble trying to differentiate L with respect to theta.
> Additionally, I don't have any idea how to represent the fact that
> \dot\theta is the same as theta.diff(t), though if I could get around the
> first issue, I could just stick theta.diff(t) in wherever I need it.
>
> Can anyone offer some insight about what I'm doing wrong?
>
> Thanks,
> Cavendish
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to