function X = trisys(A,D,C,B)
% X = trisys(A,D,C,B)
% Solution of a triangular linear system AX = B.
% It is assumed that D and B have dimension n,
% and that A and C have dimension n-1;
% A sub diagonal, input.
% D diagonal vector, input.
% C super diagonal, input.
% B right hand side vector, input.
% X solution vector, output.
n = length(B);
for k = 2:n,
mult = A(k-1)/D(k-1);
D(k) = D(k) - mult*C(k-1);
B(k) = B(k) - mult*B(k-1);
end
X(n) = B(n)/D(n);
for k = (n-1):-1:1,
X(k) = (B(k) - C(k)*X(k+1))/D(k);
end