Professional Documents
Culture Documents
Thomas Alg
Thomas Alg
Function ThomasAlg
Inputs:
Outputs:
VarArgIn Logic
Forward Elimination
Back Substitution
function x1 = ThomasAlg(AA,BB,CC,DD,varargin)
Function ThomasAlg
This function solves CFD problems using the Thomas Algorithm. The function solves
tridiagonal equations in the form of:
A(count)*x(count-1)+B(count)*x(count)+C(count)*x(count+1)=D(count)
Inputs:
A = Coefficient matrix for the first term B = Coefficient matrix of the second term C =
Coefficient matrix of the third term D = RHS matrix NN = If given, vector length
Outputs:
x = Solution matrix
VarArgIn Logic
if nargin == 4
NN = length(BB);
% If 5 are given, assign the variable to NN
elseif nargin == 5
NN = varargin{1};
% If neither is true, terminate the function
else
fprintf( '\n')
fprintf( '%s\n','Sorry, you provided an incorrect number of inputs.'
fprintf( '%s\n','This function takes 4 or 5 inputs: matricies A, B, C, and D'
fprintf( '%s\n','and an optional variable NN.' )
fprintf( '%s\n','Please try again.' )
fprintf( '\n')
error( 'Program terminated' )
end
Forward Elimination
x1 = zeros(NN,1);
Back Substitution
x1(NN) = DD(NN)/AA(NN);