# ode45 on a system of differential equations with vectors as variables

20 views (last 30 days)
Alexander on 6 Feb 2014
Answered: Amit on 6 Feb 2014
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])
Alex
Alexander on 6 Feb 2014
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 on 6 Feb 2014
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])