function acc = accof(v, f)
% Accumulate values in vector v using reduction function f.
% f must take two scalar arguments and return one scalar value.
% Returns acc, the final value of the accumulator.

acc = v(1);
for k = 2:length(v)
    acc = f([acc v(k)]);
end
