function x = tridlu(a,d,c,b) % x=tridlu(a,d,c,b) computes the solution of the tridiagonal linear system % Ax=b with lower diagonal a, main diagonal d, and upper diagonal c, using % Gaussian elimination without pivoting. % Check whether the input is in any way meaningful. n = length(d); if(length(a) ~= n-1 || length(c) ~=n-1) error('The dimensions of the input vectors are incompatible.'); end if(length(b) ~= n) error('The dimension of b is incompatible.'); end % Apply forward elimination to the matrix (i.e., update the main and the % lower diagonal. for i=1:(n-1) a(i) = a(i)/d(i); d(i+1) = d(i+1) - a(i)*c(i); end % Apply forward elimination to the right hand side. for i=2:n b(i) = b(i) - a(i-1)*b(i-1); end % Back substitution. b(n) = b(n)/d(n); for i=n-1:-1:1 b(i) = (b(i) - c(i)*b(i+1))/d(i); end x = b;