# Symbolic and Jacobian Matrix

16 views (last 30 days)
Simon Detmer on 13 May 2020
Commented: Simon Detmer on 13 May 2020
Hello,
I am currently using Matlab and the symbolic toolbox to calculate the Jacobian Matrix of different Matrix equations/state space representations.
One equation is
A=(1/m).*T*N*u
which in detail looks like this: Now I'm calculating the Jacobian of A with respect to u by using jacobian(A,u), which is just
(1/m).*T*N
Now I have 3 questions:
1. Currently I'm writing syms phi theta psi u1 u2 u3 u4 n11 n12 n13 n14 n21 ... Is there a more elegant solution to of telling Matlab that a Matrix consists of/is a symbolic variable?
2. I tried to verify the result by calculating jacobian(A,u) - (1/m).*T*N, which for some reason Matlab does not simplify. Instead it outputs for the first element for example [(n11 + n21*psi - n31*theta)/m - n11/m - (n21*psi)/m + (n31*theta)/m], which just equals to 0. Why doesnt it show 0 as result?
3. The way I'm currently doing it (see 1.), the output I get is mutiplied out. Is there a way to reverse that, so that I know that my result equals (1/m).*T*N ?
I hope someone can help me with these issues.

J Chen on 13 May 2020
Try the following. They gave what you want in Matlab R2019b.
syms m phi theta psi u1 u2 u3 u4
N = sym('n%d%d', [3 4])
T = [1 psi -theta;-psi 1 phi;theta -phi 1]
U = [u1; u2; u3; u4]
A = 1/m*T*N*U
jacobian(A,U)
fprintf('\nVerification\n')
difference = jacobian(A,U) - 1/m*T*N

#### 1 Comment

Simon Detmer on 13 May 2020
Thank you a lot, that solves my second question.
I placed some unnessecary brackets that for some reason got Matlab confused.
The creation of the N Matrix also looks nice; still is there a way to not split the matrix into its elements?
So that when calculating an Jacobian, the result also only contains the Matrix as a whole and not the elements in an outmultiplied result?