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 5bde5d5 commit 9be0356
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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. ##


Expand Down

0 comments on commit 9be0356

Please sign in to comment.