MATLAB: Question about Symbolic Differentiation

differentiationsymbolic

Hello,
If I write the following code:
syms x t
answer = diff(x,t)
then answer = 0.
Is it possible to declare that x is some unknown function of t, so that diff(x,t) will return dxdt instead of 0?
(I'm asking because I'm trying to use MATLAB to automatically derive differential equations for certain user input for a specific application.)
Thank you,
Kevin

Best Answer

If you have a fairly new version of MATLAB (R2011b I think was the first), then
syms x(t)
diff(x,t)