Symbolic and Jacobian Matrix

23 次查看(过去 30 天)
Simon Detmer
Simon Detmer 2020-5-13
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.

回答(1 个)

J Chen
J Chen 2020-5-13
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 个评论
Simon Detmer
Simon Detmer 2020-5-13
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?
Again thanks for your answer!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by