0
votes

I have a problem when computing the derivative of a first order function as below:

syms x(t)
xd = diff(x);
y = xd*xd;

how to compute derivative of y by xd;

functionalDerivative(y,xd);

Then, it raises an error as below:

Error using symengine
The variable 'diff(x(t), t)' is invalid.

The result should be:

2*diff(x,t)

I also think about name xd as a symbolic variable, then use diff(y,xd) but this way is not good for some situation. Do we have any method can directly compute the derivative of a differential function? Please suggest me some solutions. Thank in advance!

1
I can't replicate this in R2016b. Are those three lines really your only code? What version of Matlab are you using? - horchler
Yes, It is my actual code, I am using 2016a. Which is the code line you can not run? - Karim
I see what's happening. It's the functionalDerivative(y,xd); line that throws the error, not your first three lines. @TroyHaskin's approach is the way to go. - horchler

1 Answers

1
votes

I find it a little odd that the Symbolic Engine can't handle that, lacking a better word I'll borrow one from the TeX world, unexpandable expression. However, you can get around the limitation by subs-ing in a temporary variable, taking the derivative, and subs-ing it back in:

>> syms u(t)
>> dydxd = subs(functionalDerivative(subs(y,xd(t),u(t)),u),u(t),xd(t))
dydxd(t) =
2*diff(x(t), t)

Hopefully this subs approach will work in most cases, but more complex expressions for y may make it not work.