%---------------------------------------------------------  
% 質点の相互作用の計算
%---------------------------------------------------------
function dq=gfunc(t,q)

  global g;
  
  n=size(q,2);
  dq=zeros(6,n);
  
  dq(1:3,:)=q(4:6,:);

  for i=1:n
    for j=1:n
      if i ~= j
        dx=q(1:3,i)-q(1:3,j);
        r=sqrt(dx'*dx);
        dq(4:6,i)=dq(4:6,i)-g(j)*dx(1:3)/r**3;        
      end
    end
  end
