首页 > 解决方案 > How to reduce computational time in DDE simulation on Matlab

问题描述

I need to simulate a network of nodes. The weights of the edges are being given in a matrix . Due to the non-zero distances between the nodes, we consider time-delays, which are computed given the distances and an arbitrary velocity. The delay values have already been calculated. Given that A is symmetric, for a n by n matrix, we have m=n(n-1)/2 different time-delays.

load('A.mat'); % A is a symmetric matrix of dimensions n by n
load('tau.mat'); % tau is the delay array vector with n(n-1)/2 components
tf = 10;
sol = dde23(@(t,y,z)(dde(t,y,z,A)),tau,@(t)(history(t,A)),[0 tf]);
t = linspace(0,tf,200);
y = deval(sol,t);
figure
plot(t,y)

The network needs to be expressed in its analytic form as a dynamical system:

x_dot = A0* x + A1 *x(t-tau1) + ... + Am *x(t-tau_m)

, where A0 is the diagonal matrix of the initial A matrix, where it has been considered that since the distance between a node and itself is zero, there is no delay. In the absence of a way to initialize m different matrices of n by n, I created a P matrix as below. Each symmetric pair of A matrix would be put in its respective place of P and multiplied with the respective delay.

function dydt = dde(t,y,yd,A)
 n = length(A);
 A0 = diag(diag(A));
 m = n*(n-1)/2;
 P = zeros(n,n*m);
 k = 0;
 for i = 1:n
     for j = 1:n
         if j>i
             P(i,j+n*k) = A(i,j);
             P(j,i+n*k) = A(i,j);
             k = k+1;
         end
     end
 end
dydt = A0*y;
for c = 0:m-1 
    dydt = dydt + P(:,n*c+1:(c+1)*n)*yd(:,c+1);
end
end
function y = history(t,A)
y = rand(length(A),1);
end

If the code is technically correct, it is not efficient, since the time it does to produce results increase exponentially even for small number of nodes. For instance, for a network of 7 nodes it takes 2.1 seconds, for 8 nodes 7.6 seconds, for 9 nodes 30 seconds and for 10 nodes almost 121 seconds. This makes its use prohibitive for large networks. Does this make sense? Is there anything to do to decrease the time of computation?

标签: matlabsimulationdde

解决方案


推荐阅读