  function [d,condA] = Beam2_sol(n)
% d is a column n-vector with the property that d(k) is the displacement
% of the cantilever at x = k/n. condA is an estimate of cond(An).  

% Set up the upper triangular part of An is sparse format...
% The diagonal...
s = [9 6*ones(1,n-3) 5 1]; i = 1:n;       j = 1:n;
% "Add in" the superdiagonal...
s = [s -4*ones(1,n-2) -2]; i = [i 1:n-1]; j = [j 2:n];
% 'Add in" the diagonal above that...
s = [s ones(1,n-2)];       i = [i 1:n-2]; j = [j 3:n];
A = sparse(i,j,s);
% Estimate the condition of An...
condA = condest(A+A'-diag(diag(A)));
% Compute the Cholesky factorization A = R'*R where R is upper
% triangular...
R = chol(A);
% Solve the system...
d = R'\ones(n,1);
d = R\d;
d = d/n^4;
% -1 for using spdiags instead of sparse
% Beam 2 (Hung) Sparse set up of A (3 points) 
% The solve (1 point) condition (1 point)