-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
|
||
function [ud,uo,lo]=lu_tridiag(e,f,g) | ||
function [ud,uo,lo]=lu_tridiag(e,f,g); | ||
% lu_tridiag calculates the components for LU-decomposition of a tridiagonal matrix | ||
% given its off-diagonal vectors, e (a) and g (b) | ||
% and diagonal vector f (d) | ||
% the output is | ||
% the diagonal of the Upper matrix, ud (dd) | ||
% the off-diagonal of the Upper matrix, uo | ||
% and the off-diagonal of the Lower matrix, lo (bb) | ||
% note: the diagonal of the Lower matrix is all ones | ||
[m n]=size(f); | ||
ud=zeros(m,n); | ||
uo=zeros(m,n); | ||
lo=zeros(m,n); | ||
%ud(1)=f(1); | ||
%lo(1)=0; | ||
%uo=e; | ||
|
||
|
||
%for i=2:n | ||
% lo(i)=g(i)/(ud(i-1)); | ||
% ud(i)=f(i)-(lo(i)*e(i-1)); | ||
%end | ||
|
||
|
||
|
||
n=size(e); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
function x=solve_tridiag(ud,uo,lo,b); | ||
% solve_tridiag solves Ax=b for x | ||
% given | ||
% the diagonal of the Upper matrix, ud | ||
% the off-diagonal of the Upper matrix, uo | ||
% the off-diagonal of the Lower matrix, lo | ||
% the vector b | ||
% note: the diagonal of the Lower matrix is all ones | ||
|
||
[s n]=size(uo); | ||
z=zeros(s,n); | ||
z(1)=b(1); | ||
x=zeros(s,n); | ||
|
||
|
||
%solve Lz=b using forward subsitution | ||
for i= 2:n | ||
z(i)=b(i)-(lo(i)*z(i-1)); | ||
end | ||
|
||
%solve Ux=z using backward substitution | ||
x(n)=z(n)/ud(n); | ||
|
||
for k= (n-1):-1:1 | ||
|
||
x(k)=(z(k)-uo(k)*x(k+1))/ud(k); | ||
end | ||
end | ||
|
||
|