I'll work on it in the next week or so, I think should be able to get
something that does the job.
~Luke

On May 11, 11:06 pm, Ondrej Certik <ond...@certik.cz> wrote:
> On Mon, May 11, 2009 at 9:23 PM, Luke <hazelnu...@gmail.com> wrote:
>
> > Would there be any reason that the following should not be implemented:
> > t = Symbol('t')
> > q1 = Function('q1')(t)
> > solve(q1 - 1, q1)
>
> > Currently, the solve function gives:
> > ---------------------------------------------------------------------------
> > TypeError                                 Traceback (most recent call last)
>
> > /home/luke/Documents/PythonDynamics/<ipython console> in <module>()
>
> > /var/lib/python-support/python2.6/sympy/solvers/solvers.pyc in
> > solve(f, *symbols, **flags)
> >     73
> >     74     if any(not s.is_Symbol for s in symbols):
> > ---> 75         raise TypeError('not a Symbol')
> >     76
> >     77     if not isinstance(f, (tuple, list, set)):
>
> > TypeError: not a Symbol
>
> > In classical mechanics, the generalised coordinates are often treated
> > as symbols implicitly dependent upon time.  Not being able to solve
> > for their time derivatives using solve requires tedious .subs() calls
> > to replace them with symbols, solve, then replace them back with
> > Functions.
>
> Yes, I think this should be fixed. Could you please try to create a
> preliminary patch that fixes this in solve()? We'll cook it in
> sympy-patches for a while and get this in.
>
>
>
> > Similarly, is there a reason we can't differentiate with respect to a
> > Function?  For example, when using Lagrange's method for formulating
> > equations of motion, we need to differentiate the Lagrangian with
> > respect to the coordinates and with respect to the time derivatives of
> > the coordinates, and then take the time derivative....  Not being able
> > to differentiate with respect to q1.diff(t) means that one has to
> > create a dummy symbol for q1.diff(t), replace all occurances of it in
> > the Lagrangian, then take the derivative with respect to that symbol,
> > then back substitute to replace the symbol with the function, then
> > differentiate with respect to time.... a very burdensome approach
> > indeed.
>
> Yep, I think this was requested in the past too. Let's fix it.
>
>
>
> > This is what happens currently:
>
> > In [12]: diff(q3-1, q3)
> > ---------------------------------------------------------------------------
> > ValueError                                Traceback (most recent call last)
>
> > /home/luke/Documents/PythonDynamics/<ipython console> in <module>()
>
> > /var/lib/python-support/python2.6/sympy/core/multidimensional.pyc in
> > wrapper(*args, **kwargs)
> >    125                     result = apply_on_element(wrapper, args, kwargs, 
> > n)
> >    126                     return result
> > --> 127             return f(*args, **kwargs)
> >    128         wrapper.__doc__ = f.__doc__
> >    129         wrapper.__name__ = f.__name__
>
> > /var/lib/python-support/python2.6/sympy/core/function.pyc in diff(f,
> > x, times, evaluate)
> >    693     """
> >    694
> > --> 695     return Derivative(f,x,times, **{'evaluate':evaluate})
> >    696
> >    697 @vectorize(0)
>
> > /var/lib/python-support/python2.6/sympy/core/function.pyc in
> > __new__(cls, expr, *symbols, **assumptions)
> >    476             s = sympify(s)
> >    477             if not isinstance(s, Symbol):
> > --> 478                 raise ValueError('Invalid literal: %s is not a
> > valid variable' % s)
> >    479             if not expr.has(s):
> >    480                 return S.Zero
>
> > ValueError: Invalid literal: q3(t) is not a valid variable
>
> > Or is there another way this can be done easily that I'm not aware of?
>
> Currently you have to do it by hand. Try to implement this in the
> Derivative class, so that it works. It may not be obvious how to do it
> so that it looks good, but try to implement it somehow so that it
> works and we'll then refine the patch, so that it can be pushed in.
>
> E.g. my first try would be to just do all the substitutions
> automatically inside Derivative, e.g. something like
>
> if isinstance(s, Function):
>     <substitute, differentiate, substitute, return the result>
>
> Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to