From 5bde5d5592401a73b1e43b91487a36fa01c8e534 Mon Sep 17 00:00:00 2001 From: Erik R Eaton Date: Tue, 28 Mar 2017 23:41:15 -0400 Subject: [PATCH] add --- lu_tridiag.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lu_tridiag.m diff --git a/lu_tridiag.m b/lu_tridiag.m new file mode 100644 index 0000000..c47a91c --- /dev/null +++ b/lu_tridiag.m @@ -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 + +