5
$\begingroup$

I want to define a variable q which is a function of t. And I want to define another variable qdot = dq/dt.

Then what I want to archive is that if I have a function f = a*Sin[q], and when I take the derivative df = D[f,t], Mathematica returns:

a*qdot*Cos[q]. 

Is there a way to do this?

$\endgroup$
9
  • 1
    $\begingroup$ Try using Dt[] instead of D[] $\endgroup$ Commented Aug 20, 2013 at 18:58
  • $\begingroup$ You mean like this: f[t_] := a*Sin[q[t]]; D[f[t], t] gives a Cos[q[t]] q'[t] !Mathematica graphics $\endgroup$
    – Nasser
    Commented Aug 20, 2013 at 19:13
  • $\begingroup$ @belisarius The problem with Dt[] is that the constant in my function also got differentiated. $\endgroup$
    – auzn
    Commented Aug 22, 2013 at 4:14
  • $\begingroup$ @Nasser I tried your suggestion and it gives me a good result. I can even define q'[t_]:=qdot[t], so D[f[t],t] gives Cos[q[t]]qdot[t] $\endgroup$
    – auzn
    Commented Aug 22, 2013 at 14:17
  • $\begingroup$ @Nasser If this works for the OP, please consider posting an answer:) $\endgroup$
    – Kuba
    Commented Sep 23, 2013 at 23:51

1 Answer 1

8
$\begingroup$

The total derivative Dt will give you an answer assuming every symbol has a derivative, unlike the partial derivative D. To protect your constant, you can give it the attribute Constant.

SetAttributes[a, Constant]
f = a Sin[q];
Dt[f, t]
(* a Cos[q] Dt[q, t] *)
$\endgroup$
2
  • $\begingroup$ Nice experiment $\endgroup$ Commented Jun 6, 2015 at 1:12
  • $\begingroup$ Yes, definitely a worthwhile effort. I shall endeavor to do the same, my good sir! (+1) $\endgroup$
    – MarcoB
    Commented Jun 9, 2015 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.