AMAT-2120. Fall 2004. Preparation to Final Exam.
Sample programming question 2:
Write a program that calculates the position of the Center of Mass of the given system
of point masses using the formulas below.
The values of x[i],y[i],m[i] should be provided by the user
(interactively, in the command line, or through an input file).
The number of point should either be supplied by the user or counted automatically.
> x[i],y[i],m[i]; Given
> N; Given or to be counted
> xc, yc; To find
Using a vector notation
>
r[i]:=[x[i],y[i]];
position of point #i
R:=[xc, yc];
position of the center of mass
the result is given by
> R:=sum(m[i]*r[i],i=1..N)/M;
where M is the total mass of the system:
> M:=sum(m[i],i=1..N);
The above vector formula is equivalent to two scalar formulas:
>
xc:=sum(m[i]*x[i],i=1..N)/M;
yc:=sum(m[i]*y[i],i=1..N)/M;