function s = mysum(x); % compute the sum of the components of vector x s = 0; % variable to hold partial sum n = length(x); % get length of vector x for i=1:n % for each number i from 1 to n s = s + x(i); % add x(i) to the partial sum end end