Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: particle interaction
Date: Mon, 4 Feb 2008 18:31:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 57
Message-ID: <fo7ll9$6rc$1@fred.mathworks.com>
References: <fo6o84$mcu$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202149865 7020 172.30.248.35 (4 Feb 2008 18:31:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 4 Feb 2008 18:31:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:449217


"matias nordin" <matias.nordin@gmail.com> wrote in message <fo6o84
$mcu$1@fred.mathworks.com>...
> Hi everyone!
> 
> I would like to distribute N particles on a line (symmetric
> boundaries) by a function, say f(x)=sin(x), so that a small
> value gives a small spatial distances while a large value
> gives a big spatial distance. In example if f(x)= constant,
> the spatial distance between all particles is the same. So
> f(x) acts as a potential and the particles repell each other.
> 
> How to do?
> 
> Thanks for reading and helping!
> 
>   Matias
-----------
  Perhaps you are saying something like this - that the density of the particles 
is to be inversely proportional to the given function, f(x).  Or in other words, 
that the integral of the reciprocal of the function is to be proportional to the 
accumulated particle count.  Would that be an accurate statement?

  If so, that would precisely define the problem, but, depending on the 
function, it might not be easily solved.  For the sin(x) function you mentioned, 
it can be solved.  Assume that a and b are the left and right boundaries of 
your line and that 0 < a < b < pi.  If we also assume there is to be a particle 
at each boundary, you would want the x-value, xp, of the p-th particle to 
satisfy:

 (N-1)*int('csc(t)','t',a,xp) = (p-1)*int('csc(t)','t',a,b)

where "int('csc(t)','t',a,b)" means the integral of the cosecant of t (which is the 
reciprocal of sin(t)) with respect to t from a to b.  Note that for xp = a this 
would give 0 on both sides, so p would be 1.  If xp = b, then p would be N.

  If I remember my calculus correctly, the two sides of the equation evaluate 
to

 (N-1)*(log(tan(xp/2))-log(tan(a/2))) =
 (p-1)*(log(tan(b/2))-log(tan(a/2)))

We can therefore solve for xp

 xp = 2*atan(exp(((p-1)*log(tan(b/2))+(N-p)*log(tan(a/2)))/(N-1)))

  This translates in matlab to:

 p = 1:N;
 x = 2*atan(exp(((p-1)*log(tan(b/2))+(N-p)*log(tan(a/2)))/(N-1)));

which should generate the desired point spacing with vector x.

  You will note that for many functions, f(x), such a solution can become very 
much more difficult to find.

Roger Stafford