"Robert " <robertr@pitt.edu> wrote in message <j6i56v$foe$1@newscl01ah.mathworks.com>...
> Hi, I want to solve a system of the form X(t)'=A*X(t) several times with different initial conditions. Of course, I could solve it separately for each initial condition in a loop, but I was hoping that there is a vectorized method for this.
>
> Here's a more precise description of what I'm looking for: A is an NxN matrix. X0 is MxN where M is the number of initial conditions. TIME is a 1xT vector where T is the number of time bins I want for my solution. I would like a solution X that is MxNxT (or NxMxT, etc) that represents the solution to X'=A*X for each initial condition and at each time.
>
> I first tried using expm since I could apply the result to the matrix X0, but I would need to calculate expm separately at each time bin (requiring a time loop).
>
> I then thought of using ode45 since it takes a vector of times. But it takes only one initial condition (requiring a loop over X0).
>
> Any ideas?
You could use: mtimesx
http://www.mathworks.com/matlabcentral/fileexchange/25977
% Data
T = 100;
N = 3;
M = 10;
A=rand(3);
t = linspace(0,1,T);
X0 = rand(3,M); % I reverse to order
% Engine
[V D] = eig(A);
d = diag(D);
dt = d(:)*t(:).';
E = exp(dt);
E = reshape(E,1,size(A,2),length(t));
X = bsxfun(@times,V,E);
Y = V\X0;
% Solution of dX/dt = A*X and X(t=0) = X0
X = mtimesx(X,Y); % FEX
% Bruno
