From 9be035675c7e1a794d3b8e0904fd20ef61319a7e Mon Sep 17 00:00:00 2001 From: Erik R Eaton Date: Tue, 28 Mar 2017 23:42:13 -0400 Subject: [PATCH] add #2 --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 63ffaac..716e33d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,36 @@ # linear_algebra HW5 ## 2. ## +```` +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 + +```` + ## 3. ##