Skip to content

Commit

Permalink
add 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ere13004 committed Mar 29, 2017
1 parent 454ce2f commit eb89cb2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lu_tridiag.m
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));


0 comments on commit eb89cb2

Please sign in to comment.