-
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
1 changed file
with
26 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
%e, f, and j should all be vectors | ||
%A matrix must be square in order to run LU decomposition | ||
%This function will output: | ||
%diagonal of upper matrix | ||
%off diagonal of upper matrix | ||
%off diagonal of lower matrix | ||
function [ud,uo,lo]=lu_tridiag(e,f,g); | ||
ud = zeros(length(f), 1); | ||
uo = zeros(length(f)-1, 1); | ||
lo = zeros(length(f)-1, 1); | ||
|
||
lo = g; %off diagonal of lower matrix=off diagnol vectors | ||
ud(1)=f(1); %location one of upper diagonal= dignol vector at location | ||
uo(1) = g(1); %location one of upper matrix = off diagnol vector | ||
k = 2; %Starts off the while loop | ||
|
||
while k <= length(f)-1 | ||
lo(k-1) = e(k-1)/(ud(k-1)); | ||
uo(k) = g(k); | ||
ud(k) = f(k)-(lo(k-1)*uo(k-1)); | ||
k = k + 1; | ||
end | ||
lo(k-1) = e(k-1)/(ud(k-1)); %Need these two equations otherwise the last value wont work | ||
ud(k) = f(k)-(lo(k-1)*uo(k-1)); | ||
|
||
|