%% number of data points
n = 40;

%% create random data x
x = sort(rand(n, 1));

%% create a ones vector of the appropriate size. 
e = ones(size(x));

%% create the n by n sparse matrix T for every interior data point corresponding
%% to rows 2:n-1
T = (1/3) * spdiags([e, e, e], -1:1, n, n);

%% rescale first and last rows appropriately
T(1,:) = 3/2*T(1,:); T(n,:) = 3/2*T(n,:);

plot(x, 'LineWidth', 2, 'MarkerSize', 8);
hold on;
plot(T*x,  'LineWidth', 2, 'MarkerSize', 8);
legend('x', 'T*x', 'Location', 'Best');
