ode45 on a system of differential equations with vectors as variables

10 ビュー (過去 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 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