Re: [Scilab-users] function find()

2014-05-28 Thread grivet
Thank you all for your suggestions concerning pair-wise distances. The 
motivation behind my
question is that I am writing a simplistic molecular dynamics program, 
where hard disks move
freely inside a plane region, except when colliding with boudaries or 
with other disks. I hoped
that my program could be as fast as the beautiful Python program of Jake 
Vanderplas
(http://jakevdp.github.com) but, up to now, the Python code is still 
significantly faster.

JP Grive
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] function find()

2014-05-27 Thread Pierre-Aimé Agnel

Hi,

You are computing operator over complex number (which is not defined) 
because your distance matrix has an error


Try with this change
distance(i,j) = sqrt((etat(i,1)-etat(j,1))**2+(etat(i,2)-etat(j,2)**2));
=
distance(i,j) = sqrt((etat(i,1)-etat(j,1))**2+(etat(i,2)-etat(j,2))**2);

Full script:
// initialisation
diam = 0.2;
nd = 10;
etat = (rand(nd,2) -0.5)*4;
distance = zeros(nd,nd);
//compute distance matrix
for i = 1:(nd-1)
for j = (i+1):nd
distance(i,j) = 
sqrt((etat(i,1)-etat(j,1))**2+(etat(i,2)-etat(j,2))**2);

end
end
//find close pairs
[li,lj] = find(distancediam)

Best,

On 05/27/2014 01:49 PM, grivet wrote:

Hello,
While trying to compute pairwise distances between random points, I 
have come across
a behavior of function find() that I don't understand. I do the 
following:


// initialisation
diam = 0.2;
nd = 10;
etat = (rand(nd,2) -0.5)*4;
distance = zeros(nd,nd);
//compute distance matrix
for i = 1:(nd-1)
for j = (i+1):nd
distance(i,j) = 
sqrt((etat(i,1)-etat(j,1))**2+(etat(i,2)-etat(j,2)**2));

end
end
//find close pairs
[li,lj] = find(distancediam)

With both Scilab 5.4.1 and Scilab 5.5, the last line raises the error 
message:

 !--error 144
Opération non définie pour les opérandes données.

I will be grateful to anybody who spots my error.

Thank your for your time,
JP Grivet
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


--
Pierre-Aimé Agnel
Development Team
---
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.68
http://www.scilab-enterprises.com

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] function find()

2014-05-27 Thread sgougeon
Hello,

// initialisation
diam = 0.2;
nd = 10;
etat = (rand(nd,2) -0.5)*4;
distance = zeros(nd,nd);
//compute distance matrix
for i = 1:(nd-1)
 for j = (i+1):nd
 distance(i,j) = 
 sqrt((etat(i,1)-etat(j,1))**2+(etat(i,2)-etat(j,2)**2));
 end
end

You may do without explicit nested loops:

[X,Y] = meshgrid(etat(:,1), etat(:,2));
distance = sqrt((X-X.').^2 + (Y-Y.').^2)

Samuel
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users