function w = mysimpweights(n) % Computes the weights for Simpson's rule % Input: n -- the number of intervals, must be even % Output: w -- a (column) vector with the weights, length n+1 if rem(n,2) ~= 0 error('n must be even for Simpsons rule') end w = 2*ones(n+1,1); % column vector, starts all 2's w(1) = 1; w(n+1) = 1; % set ends to 1's w(2:2:n)=4; % set even # entries to 4. end