How to get the jacobian of a symbolic vector?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
The following code uses diff(X) and jacobian(r,X) in order to get velocity and accelaration of a point. However, this error appears when I try run:
"Error using sym/jacobian (line 44)
The second argument must be a vector of variables."
t is a variable (time), Phi, Theta and R are functions of t, X is a vector using Phi, Theta and R,(position of the point in cylindrical coordenates) r is function of Phi, Theta and R (position of a point in the cartesian coordenates).
syms t
Phi=sym('Phi(t)');
Theta=sym('Theta(t)');
R=sym('R(t)');
X = [Phi, Theta, R].'
dXdt=diff(X);
d2Xdt2=diff(dXdT);
r = [R*cos(Phi)*sin(Theta), R*sin(Phi)*sin(Theta), R*cos(Theta)].' %position
Ht = jacobian (r,X) %jacobian
vt=Ht*dXdt %velocity
at=Ht*d2Xdt2+diff(Ht,t)*dXdt %acceleration
=========================================================
It's strange, because the "jacobian(r,X)" works very well in the following code:
syms Phi Theta R
X = [Phi Theta R].';
r = [R*cos(Phi)*sin(Theta), R*sin(Phi)*sin(Theta), R*cos(Theta)].'
jacobian(r,X)
In this case, I can't get dXdt, but when Phi, Theta and R are functions of t, I can't get the jacobian :/
2 commentaires
John D'Errico
le 21 Mar 2015
Use the "{} Code" button to format your code. Otherwise, it shows as an unreadable mess.
Réponses (1)
John D'Errico
le 21 Mar 2015
Note that in your code, you have the lines...
dXdt=diff(X);
d2Xdt2=diff(dXdT);
MATLAB gets upset here, because you can't type. It gives the error message:
Undefined function or variable 'dXdT'.
You never defined dXdT, only dXdt.
Next, the error you get reflects a problem in your code. You have defined the FUNCTIONS, Theta, Phi and R, as parametric functions of t. They are not variables. The only variable in this is t.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!