Problem with diff(f, diff())
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Backtobasics
am 9 Sep. 2017
Kommentiert: Backtobasics
am 11 Sep. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 9 Sep. 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 Kommentare
Walter Roberson
am 10 Sep. 2017
Search your code for
2*L0(ydot*cos(thetaA+theta0)
Notice you missed the * between the L0 and what follows.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
