How should I compute the Jacobian for my equations of motion?

조회 수: 26 (최근 30일)
Noob
Noob 2025년 4월 25일
댓글: Torsten 2025년 4월 28일
Hi there!
I have a set of second-order equations of motion written symbolically in Matlab, put into matrix form using EquationsToMatrix( ). Then I convert these symbolic equations to numerical code files, using matlabFunction( ). With the numerical files, I then wrote six first-order equations of motion, in order to pass them into ode45 for simulations, in a separate simulation file. Now, I have found fixed points in my system, and I want to evaluate their stability. I am supposed to compute the Jacobian partial-derivatives matrix for the right-hand-side functions within the full set of equations of motion. How can I best compute the 6x6 Jacobian, knowing that later I have to find eigenvalues of this Jacobian matrix? Should I work numerically, symbolically, or both? If I work numerically, should I be using the gradient function, or something else?
Thanks in advance,

채택된 답변

Torsten
Torsten 2025년 4월 25일
편집: Torsten 2025년 4월 26일
According to your description, at some stage of your procedure, the right-hand side of your ODE system is available as a symbolic vector depending on the state variables y. Here, you can easily compute the Jacobian in symbolic form and later on, substitute your fixed points and compute the eigenvalues as shown below.
syms y(t)
eqn = diff(y,2) + y^2 == 4 - diff(y);
[V,S] = odeToVectorField(eqn)
V = 
S = 
% Convert the Y[i] in odeToVectorField output V to yi
V_c = feval(symengine,'evalAt',V,'Y=[y1,y2]')
V_c = 
% Evaluate jacobian with respect to yi
J = jacobian(V_c, sym('y', [1 2]))
J = 
s = symvar(J)
s = 
Jnum = double(subs(J,s(1),2))
Jnum = 2×2
0 1 -4 -1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
eig(Jnum)
ans =
-0.5000 + 1.9365i -0.5000 - 1.9365i
  댓글 수: 4
Noob
Noob 2025년 4월 26일
편집: Noob 2025년 4월 26일
HI Torsten!
Thanks so much for your answer and replies. Let me try to puzzle this out in the coming days.
I had a quick question for you, if you don't mind: Can I switch from symbolic to numerical, back and forth, using sym( ) and double( ), without any consequences, and that Matlab's computations should be trustworthy and precise? Is there something to be aware of, when switching from symoblic to numerical, and vice versa? I'm aware that some Matlab functions are symbolic-only, such as the Jacobian command, so I'm aware of this limitation, at the very least. Anything else to be mindful of?
Thanks again for your help!
Torsten
Torsten 2025년 4월 28일
The main source of errors you can encounter is due to the integration of the differential equations with the numerical solver. So don't worry about the switch from symbolic to numeric and vice versa - it's neglectable.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by