a)
function equilibrium = centerOfMass(vector) halfWeight = sum(vector)/2; % finner vektorens vekt og deler på 2 countedWeight = 0; block = 1; while countedWeight < halfWeight countedWeight = countedWeight + vector(block); block = block + 1; end equilibrium = block - 1 - ((countedWeight-halfWeight)/vector(block-1)); end
b)
line = rand (1, 13) *100; center_of_mass ( line )
c)
function [centerx,centery] = center_Of_Mass2D(mat) i = 1; for line = mat center(i) = center_Of_Mass ( line ); i = i+1; end centerx = sum(center)/length(center); center = 0; i = 1; for line = mat' center(i) = center_Of_Mass ( line ); i = i+1; end centery = sum(center)/length(center); end