Center of mass problem
6 views (last 30 days)
Show older comments
Imagine a matrix as if you're looking at a ship from above.
I have a ship and I want to store 21 containers on it, as close as possible to its center of mass.
The center of mass of the ship is (2,3) (line 2 and column 3)
The 21 containers and respective Kg's are:
containers=[100,70,30,70,10,10,100,30,70,100,10,30,30,70,100,10,70,30,70,10,10]
What code do I use in order to generate a matrix (3x7) where the cointainers are distributed in a way that the center of mass remains as close as possible to the original one (2,3).
Thanks
10 Comments
Image Analyst
on 30 Nov 2018
Edited: Image Analyst
on 30 Nov 2018
What is the size and shape of the objects? Obviously if they're dense circular lead rods then they can be packed closer to the center than if they were rectangular mattresses of the same weight.
Answers (1)
Jim Riggs
on 29 Nov 2018
Edited: Jim Riggs
on 30 Nov 2018
I wrote a function to compute the CG in X and Y. Then I used this function to find a solution by inspection (i.e. I manualy adjusted the positions until I found an answer )
function [Xcg, Ycg] = moment(D);
[row,col]=size(D);
Wtot = sum(sum(D)); % total weight of all containers
Xsum=0;
Ysum=0;
for i=1:row
for j=1:col
Xmom = D(i,j)*j; % X moment of container i,j
Ymom = D(i,j)*i; % Y moment of container i,j
Xsum = Xsum + Xmom; % total X moment
Ysum = Ysum + Ymom; % total Y moment
end
end
Xcg = Xmom/Wtot;
Ycg = Ysum/Wtot;
end
I use this function to verify that the following matrix has a CG at 3,2: (column 3, row 2):
D = [100, 70, 70, 10, 30, 10, 30;...
100, 100, 30, 70, 10, 10, 70;...
100, 70, 70, 10, 30, 10, 30]
6 Comments
Jim Riggs
on 30 Nov 2018
For complex problems like this, you need to do a lot of planning. Start with a flow chart and write in words (like I have done, above) the steos that you want to do. Then translate each step into code, breaking it down into more detail as you go.
So, it might go something like:
Step 1 make an initial allocation of the 21 containers.
Step 2 evaluate CG
Step 3 Adjust CG
Itterate step 2 and 3 until done.
Break down step 1 into sub-steps:
Make an initial alloocation:
- Sort containers into bins
- Identify bins with odd numbers
- Place odd container numbers in row 2
- Allocate remaining container pairs:
* Sort from heaviest to lighest
* Place pairs in rows 1 & 3, from heavy to light.
* Place remainder in row 2
etc..
As you go, you will identify additional functions that need to be performed, such as
- keep track of allocated/non-allocated containers
- keep track of used/available positions in the container array
Now translate each step into code and you are on your way. Obviously, this will be a whole lot of work.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!