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 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


Re: [Scilab-users] function find()

2014-05-27 Thread grivet

Le 27/05/2014 14:45, Dang, Christophe a écrit :

Hello,

Appart from the parenthetis error pointed out by Pierre-Aimé,
something imho a bit more efficient:

distance(i,j) = norm([etat(i, :) - etat(j, :)])

Best regards


Thank you Pierre-Aimé and Daniel for pointing ou this simple error.
JP Grivet
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] function find()

2014-05-27 Thread Dang, Christophe
Hello, 

Appart from the parenthetis error pointed out by Pierre-Aimé,
something imho a bit more efficient: 

distance(i,j) = norm([etat(i, :) - etat(j, :)])

Best regards

-- 
Christophe Dang Ngoc Chan
Mechanical calculation engineer

__

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error), please 
notify the sender immediately and destroy this e-mail. Any unauthorized 
copying, disclosure or distribution of the material in this e-mail is strictly 
forbidden.
__
___
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(distance
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(distanceWith 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


[Scilab-users] function find()

2014-05-27 Thread grivet

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(distanceWith 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