public double getF (int id,double x[],double y[]) {

f=0.;

for(int i=0;i<n;i++){

if(i!=id){

dx=x[id]-x[i]; dy=y[i]-y[id];

r=Math.sqrt(dx*dx+dy*dy);

// if(r>R3)f2=0.;

// else if(r>R) f2=F0*(1.5-0.5*r/R)/r;

if(r>R)f2=F0*R/r;

else f2=F0+(R-r)*(Fmax-F0)/R;

// f2=F0*R/r;

// if(r f+=f2*dx/r;

}

}

return f/n;

}

I have tested the above code with different models. (some lines has been removed, some are just comment out!)

As far as I can remembered: I did tried with Lennard-Jones potential , but I did not get a good result. (did not find the good parameter space values for the simulation).

You can tried with different model by yourself. This is the beauty of using EJS to build and test you own model.

The above code assume F(r)=-Fo/r; in the vector

**r** direction.

Then, the x component is calculated as Fx(r)=F(r)*x/r=-Fo*x/r

^{2}; (similar for Fy(r)=F(r)*y/r;)

Actually, this is Columb's Law in 2D.

For Columb's Law in 3D: The formula is the famous F(r)=-F0/r

^{2};

You can understand the above relations with Gauss Law. The model assume space is uniform.

In 3D: The surface area at r is 4*π*r

^{2} so force is proportional to r

^{-2} (or 1/r

^{2}).

In 2D: The surface area at r is 2*π*r so force is proportional to r

^{-1} (or 1/r).

Just like the B field at distance r from a straight current line is proportional to 1/r;