0% found this document useful (0 votes)
8 views1 page

Thomas

The document presents a MATLAB implementation of the Thomas algorithm, which is used to solve tridiagonal systems of linear equations. It includes a function that performs decomposition, forward substitution, and back substitution to find the solution vector. An example usage is provided with specific sub-diagonal, main diagonal, super-diagonal, and right-hand side vectors.

Uploaded by

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

Thomas

The document presents a MATLAB implementation of the Thomas algorithm, which is used to solve tridiagonal systems of linear equations. It includes a function that performs decomposition, forward substitution, and back substitution to find the solution vector. An example usage is provided with specific sub-diagonal, main diagonal, super-diagonal, and right-hand side vectors.

Uploaded by

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

[Thomas]

function x = thomas_algorithm(e, f, g, r)
% e: Sub-diagonal vector (n-1 elements)
% f: Main diagonal vector (n elements)
% g: Super-diagonal vector (n-1 elements)
% r: Right-hand side vector (n elements)

n = length(f); % Number of equations

% Decomposition and Forward substitution


for k = 2:n
e(k-1) = e(k-1) / f(k-1); % Multiplier
f(k) = f(k) - e(k-1) * g(k-1); % Update main diagonal
r(k) = r(k) - e(k-1) * r(k-1); % Update RHS vector
end

% Back substitution
x = zeros(n, 1); % Initialize solution vector
x(n) = r(n) / f(n); % Solve for last variable
for k = n-1:-1:1
x(k) = (r(k) - g(k) * x(k+1)) / f(k);
end
end

% Example Usage:
% Define the tridiagonal system from the second image
e = [-1, -1, -1]; % Sub-diagonal elements
f = [2.04, 2.04, 2.04, 2.04]; % Main diagonal elements
g = [-1, -1, -1]; % Super-diagonal elements
r = [40.8; 0.8; 0.8; 200.8]; % Right-hand side vector

% Solve the system using Thomas Algorithm


x = thomas_algorithm(e, f, g, r);

% Display the solution


disp('The solution vector T is:');
disp(x);

You might also like