Jacobian calculation of symbolic variables which are function of other variables.
Hi everyone,
I am trying to find the jacobian for a transformation matrix. I am using symbolic variables (T, l, m, n). Each of these variables are function of 4 others variables (delta1 delta2 delta3 and delta4), as:
syms u v w p q r phi theta psi x y z;
syms delta1 delta2 delta3 delta4;
% Aerodynamics
V = sqrt(u^2 + v^2 + w^2);
q_bar = (1/2) * rho * V^2;
m = (-1.35* Kf * delta1^2) + (1.35* Kf * delta2^2) + (1.35*K * Kf * delta3^2) + (-1.35* Kf * delta4^2);
l = (0.904* Kf *delta1^2) + (-0.904* Kf *delta2^2) + (0.904* Kf *delta3^2) + (-0.904* Kf *delta4^2);
n = (Km * delta1^2) + (Km * delta2^2) – (Km * delta3^2) – (Km * delta4^2);
T1= (Kf * delta1^2);
T2= (Kf * delta2^2);
T3= (Kf * delta3^2);
T4= (Kf * delta4^2);
T= T1 + T2 + T3 + T4;
phi_dot = p + tan(theta) * (q * sin(phi) + r * cos(phi));
theta_dot = q * cos(phi) – r * sin(phi);
psi_dot = (q * sin(phi) + r * cos(phi)) / cos(theta);
x_dot = cos(psi)*cos(theta)*u + (cos(psi)*sin(theta)*sin(phi) – sin(psi)*cos(phi))*v + (cos(psi)*sin(theta)*cos(phi) + sin(psi)*sin(phi))*w;
y_dot = (sin(psi)*cos(theta))*u + (sin(psi)*sin(theta)*sin(phi) + cos(psi)*cos(phi))*v + (sin(psi)*sin(theta)*cos(phi) – cos(psi)*sin(phi))*w;
z_dot = -sin(theta)*u + cos(theta)*sin(phi)*v + cos(theta)*cos(phi)*w;
f_x = – mass*g * sin(theta);
f_y = mass*g * sin(phi) * cos(theta);
f_z = mass*g * cos(phi) * cos(theta) – T ;
u_dot = r*v – q*w + (1/mass) * (f_x);
v_dot = p*w – r*u + (1/mass) * (f_y);
w_dot = q*u – p*v + (1/mass) * (f_z);
p_dot = gam(1)*p*q – gam(2)*q*r + gam(3)*l + gam(4)*n;
q_dot = gam(5)*p*r – gam(6)*(p^2 – r^2) + (1/J_yy) * m;
r_dot = gam(7)*p*q – gam(1)*q*r + gam(4)*l + gam(8)*n;
% Collect dynamics
f = [ x_dot;
y_dot;
z_dot;
phi_dot;
theta_dot;
psi_dot;
u_dot;
v_dot;
w_dot;
p_dot;
q_dot;
r_dot];
jacobian(f,[T l m n]);
So when calculating jacobian(f,[T l m n]) , i have the error:
"Invalid argument at position 2. Argument must be a variable, a symfun without a formula, or a symfun whose formula is a variable."
Can someone please give me a solution to the problem ?Hi everyone,
I am trying to find the jacobian for a transformation matrix. I am using symbolic variables (T, l, m, n). Each of these variables are function of 4 others variables (delta1 delta2 delta3 and delta4), as:
syms u v w p q r phi theta psi x y z;
syms delta1 delta2 delta3 delta4;
% Aerodynamics
V = sqrt(u^2 + v^2 + w^2);
q_bar = (1/2) * rho * V^2;
m = (-1.35* Kf * delta1^2) + (1.35* Kf * delta2^2) + (1.35*K * Kf * delta3^2) + (-1.35* Kf * delta4^2);
l = (0.904* Kf *delta1^2) + (-0.904* Kf *delta2^2) + (0.904* Kf *delta3^2) + (-0.904* Kf *delta4^2);
n = (Km * delta1^2) + (Km * delta2^2) – (Km * delta3^2) – (Km * delta4^2);
T1= (Kf * delta1^2);
T2= (Kf * delta2^2);
T3= (Kf * delta3^2);
T4= (Kf * delta4^2);
T= T1 + T2 + T3 + T4;
phi_dot = p + tan(theta) * (q * sin(phi) + r * cos(phi));
theta_dot = q * cos(phi) – r * sin(phi);
psi_dot = (q * sin(phi) + r * cos(phi)) / cos(theta);
x_dot = cos(psi)*cos(theta)*u + (cos(psi)*sin(theta)*sin(phi) – sin(psi)*cos(phi))*v + (cos(psi)*sin(theta)*cos(phi) + sin(psi)*sin(phi))*w;
y_dot = (sin(psi)*cos(theta))*u + (sin(psi)*sin(theta)*sin(phi) + cos(psi)*cos(phi))*v + (sin(psi)*sin(theta)*cos(phi) – cos(psi)*sin(phi))*w;
z_dot = -sin(theta)*u + cos(theta)*sin(phi)*v + cos(theta)*cos(phi)*w;
f_x = – mass*g * sin(theta);
f_y = mass*g * sin(phi) * cos(theta);
f_z = mass*g * cos(phi) * cos(theta) – T ;
u_dot = r*v – q*w + (1/mass) * (f_x);
v_dot = p*w – r*u + (1/mass) * (f_y);
w_dot = q*u – p*v + (1/mass) * (f_z);
p_dot = gam(1)*p*q – gam(2)*q*r + gam(3)*l + gam(4)*n;
q_dot = gam(5)*p*r – gam(6)*(p^2 – r^2) + (1/J_yy) * m;
r_dot = gam(7)*p*q – gam(1)*q*r + gam(4)*l + gam(8)*n;
% Collect dynamics
f = [ x_dot;
y_dot;
z_dot;
phi_dot;
theta_dot;
psi_dot;
u_dot;
v_dot;
w_dot;
p_dot;
q_dot;
r_dot];
jacobian(f,[T l m n]);
So when calculating jacobian(f,[T l m n]) , i have the error:
"Invalid argument at position 2. Argument must be a variable, a symfun without a formula, or a symfun whose formula is a variable."
Can someone please give me a solution to the problem ? Hi everyone,
I am trying to find the jacobian for a transformation matrix. I am using symbolic variables (T, l, m, n). Each of these variables are function of 4 others variables (delta1 delta2 delta3 and delta4), as:
syms u v w p q r phi theta psi x y z;
syms delta1 delta2 delta3 delta4;
% Aerodynamics
V = sqrt(u^2 + v^2 + w^2);
q_bar = (1/2) * rho * V^2;
m = (-1.35* Kf * delta1^2) + (1.35* Kf * delta2^2) + (1.35*K * Kf * delta3^2) + (-1.35* Kf * delta4^2);
l = (0.904* Kf *delta1^2) + (-0.904* Kf *delta2^2) + (0.904* Kf *delta3^2) + (-0.904* Kf *delta4^2);
n = (Km * delta1^2) + (Km * delta2^2) – (Km * delta3^2) – (Km * delta4^2);
T1= (Kf * delta1^2);
T2= (Kf * delta2^2);
T3= (Kf * delta3^2);
T4= (Kf * delta4^2);
T= T1 + T2 + T3 + T4;
phi_dot = p + tan(theta) * (q * sin(phi) + r * cos(phi));
theta_dot = q * cos(phi) – r * sin(phi);
psi_dot = (q * sin(phi) + r * cos(phi)) / cos(theta);
x_dot = cos(psi)*cos(theta)*u + (cos(psi)*sin(theta)*sin(phi) – sin(psi)*cos(phi))*v + (cos(psi)*sin(theta)*cos(phi) + sin(psi)*sin(phi))*w;
y_dot = (sin(psi)*cos(theta))*u + (sin(psi)*sin(theta)*sin(phi) + cos(psi)*cos(phi))*v + (sin(psi)*sin(theta)*cos(phi) – cos(psi)*sin(phi))*w;
z_dot = -sin(theta)*u + cos(theta)*sin(phi)*v + cos(theta)*cos(phi)*w;
f_x = – mass*g * sin(theta);
f_y = mass*g * sin(phi) * cos(theta);
f_z = mass*g * cos(phi) * cos(theta) – T ;
u_dot = r*v – q*w + (1/mass) * (f_x);
v_dot = p*w – r*u + (1/mass) * (f_y);
w_dot = q*u – p*v + (1/mass) * (f_z);
p_dot = gam(1)*p*q – gam(2)*q*r + gam(3)*l + gam(4)*n;
q_dot = gam(5)*p*r – gam(6)*(p^2 – r^2) + (1/J_yy) * m;
r_dot = gam(7)*p*q – gam(1)*q*r + gam(4)*l + gam(8)*n;
% Collect dynamics
f = [ x_dot;
y_dot;
z_dot;
phi_dot;
theta_dot;
psi_dot;
u_dot;
v_dot;
w_dot;
p_dot;
q_dot;
r_dot];
jacobian(f,[T l m n]);
So when calculating jacobian(f,[T l m n]) , i have the error:
"Invalid argument at position 2. Argument must be a variable, a symfun without a formula, or a symfun whose formula is a variable."
Can someone please give me a solution to the problem ? jacobian MATLAB Answers — New Questions