How to solve ODE on array variables

2 ビュー (過去 30 日間)
Telema Harry
Telema Harry 2022 年 10 月 6 日
回答済み: Sam Chak 2022 年 10 月 6 日
Ideas and suggestion needed.
I am trying to compute ODE of several array variables. I can split the equations into single equation, but that will take forever to manually compute the matrix algebra and split the equations into it's sub component, as I have several vectors and numerous equations.
See an example in the attached picture.
The question is, can I declare X1 as a column vector variable and solve the ODE on MATLAB.
Thank you for your help

採用された回答

Sam Chak
Sam Chak 2022 年 10 月 6 日
Perhaps you can do this way:
tspan = [0 0.1];
x0 = [2 1.5 1 0.5];
[t, x] = ode45(@odefcn, tspan, x0);
plot(t, x), grid on,
xlabel({'$t$'}, 'interpreter', 'latex')
ylabel({'$\mathbf{x}(t)$'}, 'interpreter', 'latex')
legend({'$x_{11}(t)$', '$x_{12}(t)$', '$x_{21}(t)$', '$x_{22}(t)$'}, 'interpreter', 'latex', 'fontsize', 14, 'location', 'northwest')
function xdot = odefcn(t, x)
xdot = zeros(4, 1);
A1 = [0 2; -2 0];
A2 = diag([0 2]*[1; 1]*[15 20]);
A = [A1 zeros(2); zeros(2) A2];
xdot = A*x;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by