Subs for variable without affecting it's derivative

26 views
Skip to first unread message

Frank Senkel

unread,
Sep 17, 2025, 4:15:04 PM (8 days ago) Sep 17
to sympy
Hi all,

I constantly run into something like cos(q)*dqdt and I want to substitute a specific value for q without it affecting dqdt say q = 0 but dqdt is non-zero. Is there a way to do this without having to make a change of variables (ie dqdt = u1 then subs for q =0)?

Thank,
Frank

Chris Smith

unread,
Sep 18, 2025, 9:12:42 AM (7 days ago) Sep 18
to sympy
You had to create dqdt manually (or else it would have evaluated to 0 already) so instead of using `q` use `f(q)` where `f=Function('f')`. When you do this something like `(q*Derivative(f(q),t)).subs(q,2)` it will now become `2*Derivative(f(2),t)` instead of 0.

Else, as you say, the masking is easy: reps = {a:Dummy() for a in eq.atoms(Derivative)};eq.xreplace(reps).subs(q,2).xreplace({v:k for k,v in reps.items()})`

/c

peter.st...@gmail.com

unread,
Sep 18, 2025, 9:20:13 AM (7 days ago) Sep 18
to sy...@googlegroups.com

I believe sympy.physics.mechanics.msubs(….)  also does not go ‘inside’ the time derivatives (?)

--
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 sympy+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sympy/5c5ba19e-00de-4a79-8fb0-10a256c3412dn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages