Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add 3
  • Loading branch information
ere13004 committed Mar 29, 2017
1 parent 1e78abf commit fa56d9e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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


0 comments on commit fa56d9e

Please sign in to comment.