Your first problem is that you did not declare a to be a symbolic function. diff() applied to a constant variable is going to yield 1, not a placeholder derivative.
syms a(x) adot
adot = diff(a);
but then you have
adot is now a function. It is not possible to define a function like f with a parameter that is a function. It is valid to define
f(x) = 3 * x + 2*adot(x)^2
Then you have
which attempts take the derivative of f with respect to a function. diff() can only take derivatives with respect to variables. There is functionalDerivative() in newer versions of MATLAB, but the best it would be able to do would be to take the derivative with respect to the function a >> functionalDerivative(f,a)
ans(x) =
-4*diff(a(x), x, x)
Perhaps you would prefer,
syms AD
f(x, AD) = subs(3 * x + 2*adot(x)^2, adot, AD)
subs(diff(f, AD), AD, adot)
The problem with this is that it assumes that adot and x are independent of each other, which is not the case.
Best Answer