Question about Symbolic Differentiation

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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Feb. de 2013
If you have a fairly new version of MATLAB (R2011b I think was the first), then
syms x(t)
diff(x,t)

6 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Feb. de 2013
don't work on (R2011b)
Walter Roberson
Walter Roberson el 13 de Feb. de 2013
Ah yes, tracking back I find that R2012a was the first to support this.
Kevin Bachovchin
Kevin Bachovchin el 13 de Feb. de 2013
Editada: Walter Roberson el 13 de Feb. de 2013
Thanks! It works on MATLAB 2012a, which I have.
However, is there still a way to maintain forcing x(t) to be a real number (instead of a complex number)?
Right now, I have
syms x1(t) x2(t) x3(t) real
It seems that when I added the function of t part, then MATLAB is treating x as a complex number instead of a real, which leads to "abs" and "conj" in my answer which I don't want.
assume(x1(t), 'real')
Kevin Bachovchin
Kevin Bachovchin el 14 de Feb. de 2013
Thanks again. When I try to take the partial derivative of function f with respect to x1(t), I'm getting an error saying Error using mupadmex Error in MuPAD command: Invalid variable. [stdlib::diff]
Is there any special way to take the partial derivative of f with respect to x1(t), or is it necessary to define a new syms x1 and substitute that in for x1(t) in f before taking the derivative?
Walter Roberson
Walter Roberson el 14 de Feb. de 2013
It is not possible to take a derivative with respect to a function.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by