a)
Code Block | ||
---|---|---|
| ||
function centerequilibrium = center_Of_Mass( line massMidpoint(vector) MhalfWeight = sum(linevector)/2; radii = 1:1:length(line); center = 1/M*sum(times(radii,line % 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)
Code Block | ||
---|---|---|
| ||
line = rand (1, 1310) *100; center_of_massmassMidpoint ( line ) |
c)
Code Block | ||
---|---|---|
| ||
function [centerxcenterX,centery centerY] = center_Of_Mass2D(mat) imassMidpoint2D(matrix) [rows, cols] = 1size(matrix); for linei = mat1:rows centeryVec(i) = center_of_mass ( line ); i = i+1sum(matrix(i, :)); end centerxcenterY = summassMidpoint(centeryVec)/length(center); centerfor = 0; i = 1; for line = mat':cols centerxVec(i) = center_of_mass ( line ); i = i+1sum(matrix(:, i)); end centerycenterX = summassMidpoint(centerxVec)/length(center); end |
...