So I've defined a variable as follows:

 q = {{x[t]}, {Φ[t]}}

I've had to differentiate with respect to time so:


Giving something like:

  q'[t]={{x'[t]}, {Φ'[t]}}

I'd now like to use a Function and have found that the following doesn't work:

fv=Function[{x, Φ}, D[V, q]][1, pi/8]

It seems that x is different to x[t]. Which seems to some regard logical, however it is now impossible to work with the Function.

 Function[{x[t],Φ[t]}, D[V, q]][1, pi/8] 

doesn't work either. Is there a way to delete the "[t]" part of each variable? Or is there a better way of going about this?

  • $\begingroup$ What do you want to get in the end? $\endgroup$ – Alexei Boulbitch Apr 15 '16 at 11:37
  • $\begingroup$ I'd like the jacobian to be evaluated and then the values x=1 and phi=pi/8 to be substituted in. So in the end a numerical value. $\endgroup$ – aenes1519 Apr 15 '16 at 12:07
  • $\begingroup$ Can you write a formula that you want in the end? $\endgroup$ – Alexei Boulbitch Apr 15 '16 at 13:10
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Apr 15 '16 at 19:03


q = {x, Φ}  
V = (x^2*m^2 + Φ^2*I)/2

fv = Function[{x, Φ}, Evaluate[Total[Flatten[D[V, {q}]]]]][1, pi/8]
(* m^2 + (I pi)/8 *)

gives the desired result, if I understand the question correctly.


If, as suggested in a comment, it is necessary that x and Φ have explicit t dependence, the following can be used instead.

q = {x[t], Φ[t]} 
V = (x[t]^2*m^2 + Φ[t]^2*I)/2
fv = Function[{x, Φ}, Evaluate[Total[Flatten[D[V, {q}]]] /. {x[t] -> x, Φ[t] -> Φ}]]
    [1, pi/8]

yielding the same result as before.

  • $\begingroup$ I haven't put the entire script in to the question so it may not make sense as to why I started with q = {x[t], [Phi][t]}. But in other parts of my script I need to differentiate with respect to t. For example with D[T,D[q,t]] where T is function dependent on on dq/dt. $\endgroup$ – aenes1519 Apr 15 '16 at 12:39
  • $\begingroup$ @aenes1519 You can use % /. {x -> x[t], Φ ->Φ[t]} to add the t dependence to the final result. $\endgroup$ – bbgodfrey Apr 15 '16 at 12:46
  • $\begingroup$ Can I also do it the other way around? %/. {x[t]->x, [Phi][t]->[Phi]} I just tried and it seems to stay the same $\endgroup$ – aenes1519 Apr 15 '16 at 12:52
  • $\begingroup$ Ignore the last comment, I managed to get it to work by understanding what "%" does. Converting from Matlab to Mathematica for symbolic calculations is proving more difficult than hoped for... $\endgroup$ – aenes1519 Apr 15 '16 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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