-
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 @@ | ||
function [ud,uo,lo]=lu_tridiag(e,f,g); | ||
%lu_tridiag The purpose of this function is to perform a LU-decomposition | ||
%by creating a lower and upper matrix from three input vectors e,f,&g. This | ||
%function is to provide a method that creates linear equations to compute | ||
%the new matrix. | ||
%Note: the inputs of the function must be vectors of the same length | ||
%--------Linear equations----------- | ||
ud = zeros(length(f), 1); %set up empty vector for new upper diagonal | ||
uo = zeros(length(f)-1, 1); %empty vector for new upper-off diagonal matrix | ||
lo = zeros(length(f)-1, 1); %empty vector for new lower-off diagonal matrix | ||
|
||
lo = g; %The value of the original upper matrix equals the new lower-off diagonal | ||
ud(1)=f(1); %first element in new upper diagonal equals first in original diagonal | ||
uo(1) = g(1); %first element in new upper-off diagonal equals that of first in g | ||
k = 2; %Set index to initialize while loop. | ||
|
||
while k <= length(f)-1 %begin loop to assign values of generic vectors e f &g | ||
lo(k-1) = e(k-1)/(ud(k-1)); %compute values for new lower-off digaonal | ||
uo(k) = g(k); %assign values to new upper-off diagonal | ||
ud(k) = f(k)-(lo(k-1)*uo(k-1)); | ||
k = k + 1; %repeat but shift to next column | ||
end | ||
lo(k-1) = e(k-1)/(ud(k-1)); %Due to indexing loop, equation is needed for final value of new lower-off diagonal | ||
ud(k) = f(k)-(lo(k-1)*uo(k-1)); %same reasoning, needed to find final value of new upper diagonal | ||
|
||
|