MATLAB Answers

0

Jacobian Matix vector of variables?

Asked by Konstantin Kramer on 20 Sep 2019
Latest activity Edited by Stephan
on 20 Sep 2019
Hello, im want to get a jacobian from this code
syms x(t) y(t) z(t);
syms u(t) v(t) w(t);
syms p(t) q(t) r(t);
syms phi(t) theta(t) psi(t);
x_p=w(t)*(sin(phi(t))*sin(psi(t)) + cos(phi(t))*cos(psi(t))*sin(theta(t))) - v(t)*(cos(phi(t))*sin(psi(t)) - cos(psi(t))*sin(phi(t))*sin(theta(t))) + cos(psi(t))*cos(theta(t))*u(t);
y_p=v(t)*(cos(phi(t))*cos(psi(t)) + sin(phi(t))*sin(psi(t))*sin(theta(t))) - w(t)*(cos(psi(t))*sin(phi(t)) - cos(phi(t))*sin(psi(t))*sin(theta(t))) + cos(theta(t))*sin(psi(t))*u(t) ;
z_p=cos(phi(t))*cos(theta(t))*w(t) - sin(theta(t))*u(t) + cos(theta(t))*sin(phi(t))*v(t);
V=[x_p,y_p,z_p];
a=[x y z];
AP=jacobian(V,a)
That my error massage
Error using sym/jacobian (line 44)
Second argument must be a vector of variables.
Can someone pls explain to me,whats causing the problem?

  0 Comments

Sign in to comment.

1 Answer

Stephan 님의 답변 20 Sep 2019
Stephan 님이 편집함. 20 Sep 2019

You have to distinguish between a symbolic variable
syms x
and a symbolic function
syms y(t)
This is why this works:
syms rho phi x y z
V = [3*phi*x^2+y; 2*rho/x*y; -x; 3*y]
a=[x y]
AP=jacobian(V,a)
V =
3*phi*x^2 + y
(2*rho*y)/x
-x
3*y
a =
[ x, y]
AP =
[ 6*phi*x, 1]
[ -(2*rho*y)/x^2, (2*rho)/x]
[ -1, 0]
[ 0, 3]
and your code does not. The second Input argument to jacobian have to be symbolic variables, not symbolic functions.

  0 Comments

Sign in to comment.