function [E,F,W]=tridiag(A,B,C,D,M,E1,F1,WM) % % TRIDIAG a function file to solve the tridiagonal matrix problem % taken from Roache, Appendix A. Notation in this file is % consistant with that in Roache. % % SYNTAX: % [E,F,W]=tridiag(A,B,C,D,M,E1,F1,WM) % % INPUT: % A = the first coefficient of the interior-point formulation % B = the second coefficient % C = the third coefficient % D = the fourth coefficient % M = the number of spatial grid points % E1 = the first coefficient from the left-hand BC % F1 = the second coefficient from the left-hand BC % WM = the right-hand BC % OUTPUT: % E = the first internal coefficient % F = the second internal coefficient % W = the dependent variable solution % % Typically all differential equations solvable by this method can be % written in the interior-point form: % % -AmWm+BmWm-CmWm=Dm % where: % m=spatial index (m=1,2,...,M-1) % % This is done by assuming two additional vectors can be created such % that: % % Wm=EmW(m-1)+Fm % % can be solved recursively % % Started 96:10:31 D.M. Glover E=zeros(1,M-1); F=zeros(1,M-1); W=zeros(1,M); E(1)=E1; F(1)=F1; for j=2:M-1 E(j)=A(j)/(B(j)-C(j)*E(j-1)); F(j)=(D(j)+C(j)*F(j-1))/(B(j)-C(j)*E(j-1)); end W(M)=WM; for j=(M-1):-1:1 W(j)=E(j)*W(j+1)+F(j); end