How to solve multi-variable system of ODEs
10 views (last 30 days)
Show older comments
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)?
0 Comments
Accepted Answer
Torsten
on 4 Oct 2018
[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 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!