Thanks for the quick reply. Perhaps it's a version issue. I'm using 0.7.1.
When I try:
r,b,t = symbols("r,b,t")
theta = Function('theta')
x = (r+b)*sin(theta) + r*theta*cos(theta)
I get:
---------------------------------------------------------------------------TypeError
Traceback (most recent call
last)<ipython-input-295-cd4ee94c1264> in <module>() 2 theta =
Function('theta') 3 ----> 4 x = (r+b)*sin(theta) + r*theta*cos(theta)
/usr/local/lib/python2.7/dist-packages/sympy/core/cache.pyc in wrapper(*args,
**kw_args) 99 except KeyError: 100 pass--> 101
func_cache_it_cache[k] = r = func(*args, **kw_args) 102 return r
103 return wrapper
/usr/local/lib/python2.7/dist-packages/sympy/core/function.pyc in __new__(cls,
*args, **options) 172 evaluate = options.pop('evaluate', True)
173 if evaluate:--> 174 evaluated = cls.eval(*args) 175
if evaluated is not None: 176 return evaluated
/usr/local/lib/python2.7/dist-packages/sympy/functions/elementary/trigonometric.pyc
in eval(cls, arg) 159 return 160 --> 161 if
arg.could_extract_minus_sign(): 162 return -cls(-arg) 163
TypeError: unbound method could_extract_minus_sign() must be called with theta
instance as first argument (got nothing instead)
I'll upgrade and see if that fixes things.
Cavendish
On Tuesday, October 15, 2013 5:24:56 PM UTC-4, Aaron Meurer wrote:
>
> 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] <javascript:>> 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] <javascript:>.
> > To post to this group, send email to [email protected]<javascript:>.
>
> > 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.