From fa56d9edbf00a11c47ed5c3cf0985910e3f1a416 Mon Sep 17 00:00:00 2001 From: Erik R Eaton Date: Tue, 28 Mar 2017 23:57:52 -0400 Subject: [PATCH] add 3 --- solve_tridiag.m | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 solve_tridiag.m diff --git a/solve_tridiag.m b/solve_tridiag.m new file mode 100644 index 0000000..e04a4d0 --- /dev/null +++ b/solve_tridiag.m @@ -0,0 +1,23 @@ +function x=solve_tridiag(ud,uo,lo,b); +%solve_tridiag The purpose of this function is to solve common equation +%Ax=b given the diagonal of the upper matrix(ud), and the off diagonals +%(uo,lo) and the vector b. The procedure similar to Cholesky factorization. + +n = length(b); %set dimension of n based on input vector +x = zeros(n,1); %create an empty vector to store values of length n +y = zeros(n,1); % create an empty vector to store values of length n that will be manipulated +y(1) = b(1); %Assign the first y value to equal the first value of vector b (equal to one) + +%Set up iterative procedure to back solve for the vectors of the off +%diagonals. (similar to Cholesky's step procedure). +for i=2:n %for loop beginning with second element + y(i)=b(i)-lo(i-1)*y(i-1); %utilize the first given input to calculate the first value of the lower off diagonal + +end + +x(n) = y(n)/ud(n); +for i=n-1:1 %procedure to algebraically find the values of the upper diagonal + x(i)=(y(i)-uo(i)*x(i+1))/ud(i); +end + +