ode45 on a system of differential equations with vectors as variables

조회 수: 5 (최근 30일)
Alexander
Alexander 2014년 2월 6일
답변: Amit 2014년 2월 6일
Hi all,
I have a system of differential equations:
dX/dT = -X + (1 - X) .* (W(R ) * F(X))
where ".*" means element-wise mulitplication.
dR/dT = c.G(F(X))
where X and R are vectors of equal length, W returns a square matrix with dimensions equal to the length of X, F(x) and G(x) are sigmoid functions each returning a vector and c is a constant.
I've been trying to use ode45 to find numerical solutions for this system but have come across the problem that the initial conditions input, which needs to be a n x 2 matrix of column vectors X0 and R0, seems to get concatenated into a vector of length 2n.
Is it possible to use ode45 on differential equations with vector variables? Should I just split the input vector inside the function definition for the ode system?
At the moment I have:
function xprime = diffs(t,x)
rho = 0.0001;
xprime(1) = -x(:,1) + (1 - x(:,1)) .* (W(x(:,2)) * F(x(:,1)));
xprime(2) = rho * G(F(x(:,1)));
end
and I call it with:
[t,x] = ode45(@diffs,[0 10],[X R])
any help is much appreciated. Thanks in advance for your time.
Alex
  댓글 수: 1
Alexander
Alexander 2014년 2월 6일
I've altered my "diffs" function to:
function xprime = diffs(t,x)
rho = 0.0001;
l = length(x);
X = x(1:l/2);
R = x(l/2+1:l);
xprime(1:l/2) = -X + (1 - X) .* (W(R) * F(X));
xprime(l/2+1:l) = rho * G(F(X));
xprime = transpose(xprime);
end
and it seems to be reasonably happy.
If there's a better way of doing this I would still like to know.
Thanks again.

댓글을 달려면 로그인하십시오.

채택된 답변

Amit
Amit 2014년 2월 6일
function xprime = diffs(t,x)
rho = 0.0001;
len_xx = numel(x);
xprime = zeros(len_xx,1);
xprime(1:len_xx/2) = -x(1:len_xx/2) + (1 - x(1:len_xx/2)) .* (W(x(1:len_xx/2)) * F(x(1:len_xx/2,1)));
xprime(len_xx/2+1:end) = rho * G(F(x(len_xx/2+1:end)));
end
now, you can run this as:
[t,x] = ode45(@diffs,[0 10],[X;R])

추가 답변 (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