File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 11% ==========================================================================
22%
3- % tridiagonal Solves the tridiagonal linear system Ax= d for x using the
3+ % tridiagonal Solves the tridiagonal linear system Ax = d for x using the
44% tridiagonal matrix algorithm (i.e. the Thomas algorithm).
55%
66% x = tridiagonal(A,d)
77%
88% Copyright © 2021 Tamas Kis
9- % Last Update: 2022-04-16
9+ % Last Update: 2022-10-11
1010% Website: https://tamaskis.github.io
11111212%
1313% TECHNICAL DOCUMENTATION:
14- % https://tamaskis.github.io/documentation /Tridiagonal_Matrix_Algorithm__Thomas_Algorithm_.pdf
14+ % https://tamaskis.github.io/files /Tridiagonal_Matrix_Algorithm__Thomas_Algorithm_.pdf
1515%
1616% --------------------------------------------------------------------------
1717%
2424% -------
2525% OUTPUT:
2626% -------
27- % x - (n×1 double) solution of the tridiagonal linear system Ax= d
27+ % x - (n×1 double) solution of the tridiagonal linear system Ax = d
2828%
2929% ==========================================================================
3030function x = tridiagonal(A ,d )
31-
31+
3232 % determines n
3333 n = length(d );
3434
4040
4141 % extracts first element of "b" from "A"
4242 b(1 ) = A(1 ,1 );
43-
43+
4444 % forward loop
4545 for i = 2 : n
46-
46+
4747 % extract relevant elements of "a", "b", and "c" from "A"
4848 a(i - 1 ) = A(i ,i - 1 );
4949 b(i ) = A(i ,i );
5050 c(i - 1 ) = A(i - 1 ,i );
51-
51+
5252 % forward elimination
5353 w = a(i - 1 )/b(i - 1 );
5454 b(i ) = b(i )-w * c(i - 1 );
5555 d(i ) = d(i )-w * d(i - 1 );
56-
56+
5757 end
5858
5959 % backward loop (backward substitution)
You can’t perform that action at this time.
0 commit comments