How to use jacobian after odeToVectorField
7 ビュー (過去 30 日間)
古いコメントを表示
good evening, i don't understand what's the variables name of the output vector of the function odeToVectorField, the problem is that both the documentation and the vector have this notation Y[1] which is not a possible name for a variable as far as i know. If i try to use Y_1 as a variable it dosen't work but i can't use the real name either because it gives me an error, does anyone have an idea?
syms theta_1(t) theta_2(t) L_1 L_2 m_1 m_2 g
x_1 = L_1*sin(theta_1);
y_1 = -L_1*cos(theta_1);
x_2 = x_1 + L_2*sin(theta_2);
y_2 = y_1 - L_2*cos(theta_2);
vx_1 = diff(x_1);
vy_1 = diff(y_1);
vx_2 = diff(x_2);
vy_2 = diff(y_2);
ax_1 = diff(vx_1);
ay_1 = diff(vy_1);
ax_2 = diff(vx_2);
ay_2 = diff(vy_2);
syms T_1 T_2
eqx_1 = m_1*ax_1(t) == -T_1*sin(theta_1(t)) + T_2*sin(theta_2(t));
eqy_1 = m_1*ay_1(t) == T_1*cos(theta_1(t)) - T_2*cos(theta_2(t)) - m_1*g;
eqx_2 = m_2*ax_2(t) == -T_2*sin(theta_2(t));
eqy_2 = m_2*ay_2(t) == T_2*cos(theta_2(t)) - m_2*g;
Tension = solve([eqx_1 eqy_1],[T_1 T_2]);
eqRed_1 = subs(eqx_2,[T_1 T_2],[Tension.T_1 Tension.T_2]);
eqRed_2 = subs(eqy_2,[T_1 T_2],[Tension.T_1 Tension.T_2]);
L_1 = 1;
L_2 = 1.5;
m_1 = 2;
m_2 = 1;
g = 9.8;
eqn_1 = subs(eqRed_1);
eqn_2 = subs(eqRed_2);
[V,S] = odeToVectorField(eqn_1,eqn_2);
jacob = jacobian(V,sym('Y',[1 4]))
subs(jacob,sym('Y',[1 4]),[0 0 0 0])
sym('Y[1]')
1 件のコメント
回答 (1 件)
Sakshay
2022 年 12 月 1 日
Hello Gabriele,
As per my understanding you want to use the output of the "odeToVectorField" for further processing using symbolic expressions, like the "jacobian" function.
Currently, MATLAB only supports generating a "matlabFunction" from the output of "odeToVectorField" function. The symbolic variable used to construct the output of “odeToVectorField” is “Y”. This variable allows for the generation of a MATLAB function handle.
However, you can use a workaround for the same to convert the “Y[i]” to “yi”, in the output of “odeToVectorField” function. This would enable to use this output in the “jacobian” function for further processing. A sample code would look like:
% Convert the Y[i] in odeToVectorField output V to yi
V_c = feval(symengine,'evalAt',V,'Y=[y1,y2,y3,y4]');
% Evaluate jacobian with respect to yi
jacob = jacobian(V_c, sym('y', [1 4]));
For more information on "odeToVectorField" function, you can refer to the following documentation:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!