필터 지우기
필터 지우기

How to build a vector for a system of ODEs

조회 수: 2 (최근 30일)
2Lindsay2
2Lindsay2 2018년 8월 1일
Hi,
I'm looking to automate some code used to solve systems of ODEs. Right now I'm having to type in my system of ODEs to be solve, but as the problems get bigger, and as I need more equations, I'd really like to have it done for me. This is the code I wrote to try to achieve this, however as I build dxdt and dydt in the nested for loop the actual indices aren't getting inserted into the equations, the i's and j's get left in there and I get the error telling me my indices need to be real or positive when I try to solve it. Is there a way to get the numbers to stay for my indexing?
Thanks in advance
N = 2;
gamma1 = 1;
gamma2 = 2;
x0 = [1 2]; %Initial Conditions
y0 = [1 1];
sum = 0;
for j = 1:N
for i = 1:N
if(i ~= j)
dxdt{j} = @(t,x) gamma(i)/2/pi*-1*(x(j)-x(i))/((x(j+N)-x(i+N))^2 + (x(j)-x(i)));
dydt{j} = @(t,x) gamma(i)/2/pi*(x(j+N)-x(i+N))/((x(j+N)-x(i+N))^2 + (x(j)-x(i)));
end
end
end
for i = 1:N
f{i}= @(t,x) dxdt{i};
end
for i = 1:N
f{i+N}= @(t,x) dydt{i};
end
[t,x] = ode113(@(t,x) f(t,x), [0 200], [y0 x0]);
plot(x(:,3),x(:,1), 'r', x(:,4),x(:,2), 'b')

답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by