MATLAB Coding
Thomas Algorithm:
(To solve Tri-diagonal system of equations)
function x = thomasfunc(a,b,c,r)
%Here thomasfunc(a,b,c,r) makes use of Thomas algorithm to calculate the
%value of x for a tridiagonal system
%a denotes lower diagonal of matrix A [0 a2 a3 a4]
%b denotes main diagonal of A [b1 b2 b3 b4]
%c denotes upper diagonal of A [c1 c2 c3 0]
%r denotes right hand side vector b
gamma(1)=c(1)/b(1);
rho(1)=r(1)/b(1);
n=size(a,2);
for i =2:n
gamma(i)=c(i)/(b(i)-a(i)*gamma(i-1));
rho(i)=(r(i)-a(i)*rho(i-1))/(b(i)-a(i)*gamma(i-1));
end
x(n)=rho(n);
for i = 1:n-1
x(n-i)=rho(n-i)-gamma(n-i)*x(n-i+1);
end
x=transpose(x);
end