How to solve multi-variable system of ODEs

14 ビュー (過去 30 日間)
2Lindsay2
2Lindsay2 2018 年 10 月 3 日
回答済み: Torsten 2018 年 10 月 4 日
I want to solve a system of 4 nonlinear ODEs with two variables x and y. I'm using the code below to try to achieve the solution.
g = @(t, x, y) [
gamma2/2/pi*((x(1)-x(2)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2));
gamma1/2/pi*((x(2)-x(1)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2));
gamma2/2/pi*(-(y(1)-y(2)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2));
gamma1/2/pi*(-(y(2)-y(1)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2))
];
[t, x, y] = ode45(g, [0 200], [y1_0 y2_0 x1_0 x2_0]);
Where gamma1, gamma2, y1_0, y2_0, x1_0, and x2_0 are constants.
Is there a way to use two variable like this? Or do I have to simplify the expression further by assigning y1 = x(1), y2 = x(2), x1 = x(3), x2 = x(4)?

採用された回答

Torsten
Torsten 2018 年 10 月 4 日
[t z] = ode45(@(t,z)g(t,z,gamma1,gamma2), [0 200], [y1_0 y2_0 x1_0 x2_0]);
function dz = g(t,z,gamma1,gamma2)
y = z(1:2);
x = z(3:4);
dz = [gamma2/2/pi*((x(1)-x(2)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2));
gamma1/2/pi*((x(2)-x(1)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2));
gamma2/2/pi*(-(y(1)-y(2)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2));
gamma1/2/pi*(-(y(2)-y(1)) / ((x(1)-x(2))^2 + (y(1)-y(2))^2))];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by