0% found this document useful (0 votes)
37 views2 pages

Thomas Algorithm Programme:-: 2.04a-B 40.8 - A+2.04b 0.8 - b+2.04c 0.8 - c+2.04d 200.8

The document provides an example problem to solve a system of linear equations using the Thomas algorithm. It gives the equations 2.04a-b= 40.8, -a+2.04b= 0.8, -b+2.04c= 0.8, -c+2.04d=200.8. It then provides the Matlab code for the Thomas algorithm, which uses forward elimination to solve for the diagonal and upper diagonal terms, and back substitution to solve for the values of the variables a, b, c, d. The code prints out the solution values for each variable.

Uploaded by

Manvinder Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Thomas Algorithm Programme:-: 2.04a-B 40.8 - A+2.04b 0.8 - b+2.04c 0.8 - c+2.04d 200.8

The document provides an example problem to solve a system of linear equations using the Thomas algorithm. It gives the equations 2.04a-b= 40.8, -a+2.04b= 0.8, -b+2.04c= 0.8, -c+2.04d=200.8. It then provides the Matlab code for the Thomas algorithm, which uses forward elimination to solve for the diagonal and upper diagonal terms, and back substitution to solve for the values of the variables a, b, c, d. The code prints out the solution values for each variable.

Uploaded by

Manvinder Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Thomas algorithm Programme:-

Q. Solve the following equation using Thomas algorithm:-


2.04a-b= 40.8
-a+2.04b= 0.8
-b+2.04c= 0.8
-c+2.04d=200.8

Code:-

function x= thomas(e,f,g,r)
%input
%e= subdiagonal vector
%f=diagonal vector
%g=super diagonal matrix
%r=right handside vector
%x= solution
n=length(f);
%forward elimination
for k=2:n
factor=e(k)/f(k-1);
f(k)=f(k)-factor*g(k-1);
r(k)=r(k)-factor*r(k-1);
end
%back subsitution
x(n)=r(n)/f(n);
for k=n-1:-1:1
x(k)=(r(k)-g(k)*x(k+1))/f(k);
end
for i=1:length(x)
fprintf('\nx%d=%f\n',i,x(i));
end

Output:-

You might also like