Post Reply 
Center of Mass - Matrix Representation
04-08-2015, 07:35 PM
Post: #6
RE: Center of Mass - Matrix Representation
The following program computes the center of mass for arbitrary arrangements of mass points in 3D cartesian space. For a system consisting of n particles the input is a n-by-4 matrix, e.g. the x, y, z coordinates in the the first three columns and the masses in the forth column.

Code:
EXPORT CG(xyzm)
BEGIN
  LOCAL s,r,c,t,x,y,z,m;
  LOCAL mt,cx,cy,cz;
  s:=SIZE(xyzm);
  r:=s(1);
  c:=s(1);
  t:=TRN(xyzm);
  x:=t(1);
  y:=t(2);
  z:=t(3);
  m:=t(4);
  mt:=ΣLIST(m);
  cx:=DOT(x,m)/mt;
  cy:=DOT(y,m)/mt;
  cz:=DOT(z,m)/mt;
  RETURN [[cx,cy,cz]];
END;

Using akmon's example:
Code:
CG([[0 0 0 1][5 0 0 1][5 5 0 1]]) = [3.333333333 1.666666667 0] = [10/3 5/3 0]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Center of Mass - Matrix Representation - Thomas Ritschel - 04-08-2015 07:35 PM



User(s) browsing this thread: 1 Guest(s)