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

26 次查看(过去 30 天)
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