1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| function test
N = 1000;
X = rand(N,4);
for n=1:5
tic
for i=1:N
for j=1:N
B = exp(-norm(X(i,:)-X(j,:))^2);
end
end
t(1,n) = toc;
tic
for i=1:N
for j=i:N
BB = exp(-norm(X(i,:)-X(j,:))^2);
end
end
t(2,n) = toc;
tic
for i=1:N
for j=i+1:N
BBB = exp(-norm(X(i,:)-X(j,:))^2);
end
end
t(3,n) = toc;
tic
for i=1:N
for j=i+1:N
BBBB = exp(-((X(i,1)-X(j,1))^2 + ...
(X(i,2)-X(j,2))^2 + ...
(X(i,3)-X(j,3))^2 + ...
(X(i,4)-X(j,4))^2));
end
end
t(4,n) = toc;
end
mean(t,2) |
Partager