function [Lsub,Udiag,Usup] = midtermQ7(c,d,e,vecwise)
% GE without pivoting applied to T = tridag(c,d,e)
% returns subdiagonal of L, diagonal of U, superdiagonal of U
% no need to return diagonal of L since it is all ones
% vecwise = 0: use a loop
% vecwise = 1: use vector operations: fails!
%
n = length(d);
Lsub = zeros(n-1,1);
Usup = e; % superdiagonal of U is unchanged from superdiagonal of T
Udiag = zeros(n,1);
Udiag(1) = d(1); % U(1,1)
if ~vecwise
    for i=1:n-1
        mult = c(i)/d(i);
        d(i+1) = d(i+1) - mult*e(i);
        Udiag(i+1) = d(i+1); % U(i+1,i+1)
        Lsub(i) = mult;
    end
else % note that the following DOES NOT work
    Lsub = c ./ d(1:n-1); % multipliers
    d(2:n) = d(2:n) - Lsub .* e;
end
    
    