How to get the jacobian of a symbolic vector?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marlon Saveri Silva
el 21 de Mzo. de 2015
Comentada: Marlon Saveri Silva
el 21 de Mzo. de 2015
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 comentarios
John D'Errico
el 21 de Mzo. de 2015
Use the "{} Code" button to format your code. Otherwise, it shows as an unreadable mess.
Respuestas (1)
John D'Errico
el 21 de Mzo. de 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.
2 comentarios
Marlon Saveri Silva
el 21 de Mzo. de 2015
Editada: Marlon Saveri Silva
el 21 de Mzo. de 2015
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!