Center of Mass - Matrix Representation
04-05-2015, 04:05 AM
Post: #1
 Eddie W. Shore Senior Member Posts: 975 Joined: Dec 2013
Center of Mass - Matrix Representation
The HP Prime program CENTERMTX calculates the center of mass of the matrix M, where M represents the body. The entries of M represents an array of molecules, each with assigned weights. It is possible that the center of mass is located outside of the body.

Note: If gravity affects the particles equally, then the center of mass & center of gravity are identical.

Formulas:

Xc = ∑(x * m)/∑m
Yc = ∑(y * m)/∑m

HP Prime: CENTERMTX

Code:
EXPORT CENTERMTX(m) BEGIN // Center of Mass: matrix // Matrix of mass LOCAL s,tm,rt,ct,r,c; // in MAKEMAT I=row,J=col s:=SIZE(m); r:=s(1); c:=s(2); // Total Mass tm:=TRN(m*MAKEMAT(1,c,1))* MAKEMAT(1,r,1); tm:=tm(1,1); // Row Total rt:=TRN(m*MAKEMAT(I,c,1))* MAKEMAT(1,r,1); rt:=rt(1,1); // Column Total ct:=TRN(TRN(m)*MAKEMAT(I,r,1))* MAKEMAT(1,c,1); ct:=ct(1,1); // center RETURN [[rt/tm,ct/tm]]; END;

Example: Locate the center of mass of the following body.

M = [[1 , 2, 1], [1, 1, 2],[1, 2, 1]]

The center of mass: [[ 2.08333333333, 2 ]]

http://edspi31415.blogspot.com/2015/04/h...atrix.html
04-05-2015, 10:29 PM
Post: #2
 akmon Member Posts: 186 Joined: Jun 2014
RE: Center of Mass - Matrix Representation
Congrats for your program, I´m going to download to my calculator. This is the first step for simebody who wants to program the famous and impressive "Sección" program for HP48 or 50, with gravity center, moments of inertia etc, on any shape, any.
04-06-2015, 03:09 PM
Post: #3
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Center of Mass - Matrix Representation
(04-05-2015 10:29 PM)akmon Wrote:  Congrats for your program, I´m going to download to my calculator. This is the first step for simebody who wants to program the famous and impressive "Sección" program for HP48 or 50, with gravity center, moments of inertia etc, on any shape, any.

I quote!
thank you, Eddie

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
04-07-2015, 06:33 AM
Post: #4
 akmon Member Posts: 186 Joined: Jun 2014
RE: Center of Mass - Matrix Representation
I´ve tried a little example to manage the program, but I didn´t get the results I expected. I want to know the center of gravity of a triangle. The coordinates are (0,0), (5,0) and (5,5). I suppose mass 1 for every points, so I write this matrix:

[[0 0 1][5 0 1][5 5 1]]

The gravity center sould be (10/3 5/3), but I don´t get that result. What am I doing bad? Thank you.
04-08-2015, 05:48 PM (This post was last modified: 04-08-2015 05:51 PM by Thomas Ritschel.)
Post: #5
 Thomas Ritschel Member Posts: 66 Joined: Feb 2014
RE: Center of Mass - Matrix Representation
(04-07-2015 06:33 AM)akmon Wrote:  I´ve tried a little example to manage the program, but I didn´t get the results I expected. I want to know the center of gravity of a triangle. The coordinates are (0,0), (5,0) and (5,5). I suppose mass 1 for every points, so I write this matrix:

[[0 0 1][5 0 1][5 5 1]]

The gravity center sould be (10/3 5/3), but I don´t get that result. What am I doing bad? Thank you.

Note that the matrix does not contain the coordinates and associated masses, but rather it's a grid representation of point masses. There is an explanation of the matrix in Eddie's blog.

For your example the matrix may be entered as (6x6 matrix, e.g. 0 to 5 = 6 grid points):

[[1 0 0 0 0 1][0 0 0 0 0 0][0 0 0 0 0 0][0 0 0 0 0 0][0 0 0 0 0 0][0 0 0 0 0 1]]

This will yield the center of mass at grid position (13/3 8/3), having a (+1 +1) offset with respect to your solution (note that the origin (0 0) is at grid position (1 1)).
04-08-2015, 07:35 PM
Post: #6
 Thomas Ritschel Member Posts: 66 Joined: Feb 2014
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]
04-09-2015, 10:48 AM
Post: #7
 akmon Member Posts: 186 Joined: Jun 2014
RE: Center of Mass - Matrix Representation
Thank you very much for your version, Thomas. That´s what I was searching, easier for matrix input, even I edited it simpler, because 99% I work in 2D only.
07-03-2015, 03:40 PM (This post was last modified: 07-03-2015 03:50 PM by chromos.)
Post: #8
 chromos Member Posts: 177 Joined: Jun 2015
RE: Center of Mass - Matrix Representation
(04-07-2015 06:33 AM)akmon Wrote:  I´ve tried a little example to manage the program, but I didn´t get the results I expected. I want to know the center of gravity of a triangle. The coordinates are (0,0), (5,0) and (5,5). I suppose mass 1 for every points, so I write this matrix:

[[0 0 1][5 0 1][5 5 1]]

The gravity center sould be (10/3 5/3), but I don´t get that result. What am I doing bad? Thank you.

There is built-in function in HP Prime for this.

Geocaching Coords Solver, Number of triangles Puzzle
 « Next Oldest | Next Newest »

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