Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagenone
function equilibrium = centerOfMassmassMidpoint(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

...

Code Block
languagenone
line = rand (1, 10) *100;
centerOfMassmassMidpoint ( line )

c)

Code Block
languagenone
function [centerX, centerY] = centerOfMass2DmassMidpoint2D(matrix)
[rows, cols] = size(matrix);
for i = 1:rows
    yVec(i) = sum(matrix(i, :));
end
centerY = centerOfMassmassMidpoint(yVec);
for i = 1:cols
    xVec(i) = sum(matrix(:, i));
end
centerX = centerOfMassmassMidpoint(xVec);
end