Problem with diff(f, diff())
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Backtobasics
el 9 de Sept. de 2017
Comentada: Backtobasics
el 11 de Sept. de 2017
Hi there,
I want to differentiate a long equasion L with respect to thetaAdot and ran into a problem. I managed to break it down to the following:
Example 1:
syms x a
f(x, a)=3*x+2*a^2;
df=diff(f, a)
ans=4a -> perfectly fine
Example 2:
syms x a adot
adot=diff(a);
f(x, adot)=3*x+2*adot^2;
df=diff(f, adot)
-> Error
It seems MATLAB has a problem with the derivative but I cannot figure out why? Can you help me with this?
Thank you in advance!
0 comentarios
Respuesta aceptada
Walter Roberson
el 9 de Sept. de 2017
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
f(x, adot)=3*x+2*adot^2;
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
df=diff(f, adot)
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.
3 comentarios
Walter Roberson
el 10 de Sept. de 2017
Search your code for
2*L0(ydot*cos(thetaA+theta0)
Notice you missed the * between the L0 and what follows.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
