34 views (last 30 days)

Show older comments

A about 21 hours ago

Commented: A about 18 hours ago

Open in MATLAB Online

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 ?

##### 0 Comments Show -2 older commentsHide -2 older comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

### Answers (1)

Steven Lord about 21 hours ago

Open in MATLAB Online

I tried running your code but there are several variables that are not defined: rho, Kf, K, Km, mass, g, gam, J_yy. Specifying dummy values for those variables, let's look at your f variable and see if it's functions of T, l, m, and n.

rho = 42;

Kf = 999;

K = 17;

Km = 18;

mass = 12345;

g = 9.8;

gam = 9:-1:1;

J_yy = 343455;

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]

f=

I don't see variables named T, l, m, or n in the array f. You have defined expressions in T, l, m, and n but you cannot use those as the second input to the jacobian function. Take a look at T:

T

T=

What exactly would you expect the derivative of f(10) with respect to T to be?

f(10)

ans=

##### 3 Comments Show 1 older commentHide 1 older comment

Show 1 older commentHide 1 older comment

A about 20 hours ago

#### Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2143031-jacobian-calculation-of-symbolic-variables-which-are-function-of-other-variables#comment_3230186

Open in MATLAB Online

Sorry, i forgot to share the constants (rho, g , ...) because it was defined in another script, here are my values:

rho = 1.225;

Kf = 0.0121;

K = 1;

Km = 3.5e-04;

mass = 60;

g = 9.8;

gam = [0.1752 0.7835 0.365 0.0036 0.65 0.2042 0.2204 0.025];

J_yy = 16.53;

the array f includes variables which contains the variables T,l,m,n so technically, it contains these variables.

My objective is to linearize my non-linear system to obtain a state space representation, with this code:

vars = [x y z u v w p q r phi theta psi T l m n];

trim = [1000 1000 -1000 0 0 0 0 0 0 0 0 0 mass*g 0 0 0];

A_lon = double(subs(jacobian(f,[x y z phi theta psi u v w p q r]),vars,trim));

% B_lon = double(subs(jacobian(f,[delta_t_mr1 delta_t_mr2 delta_t_mr3 delta_t_mr4]),vars,trim));

B_lon = double(subs(jacobian(f,[T l m n]),vars,trim));

I get the A matrix without any problem. But when comming to the B matrix, i get the error.

I actually want (T, l, m, n) as inputs for my system. That's why, i don't want to use the variables (delta1 delta2 delta3 delta4) in the B jacobian.

Steven Lord about 19 hours ago

#### Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2143031-jacobian-calculation-of-symbolic-variables-which-are-function-of-other-variables#comment_3230201

the array f includes variables which contains the variables T,l,m,n so technically, it contains these variables.

Which element of f contains the character T?

The array f was created using the expressions stored in the variable T, but that's not the same as saying that f contains the variable T.

To repeat my question from the end of my answer, what exactly would you expect the derivative of f(10) with respect to T to be? [You can use the values of the constants from your comment instead of the dummy values I added to generate f(10), but show us the values of T, f(10), and the specific value you expect to have.]

A about 18 hours ago

#### Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2143031-jacobian-calculation-of-symbolic-variables-which-are-function-of-other-variables#comment_3230311

The derivative of f(10) with respect to T should be -1/mass, which should give -0.016667. That's what I am trying to verify with my script.

Sign in to comment.

Sign in to answer this question.

### See Also

### Tags

- jacobian

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

- América Latina (Español)
- Canada (English)
- United States (English)

Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français

- United Kingdom(English)

Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

Contact your local office