Skip to content
Permalink
b649d6ed1c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
23 lines (17 sloc) 1019 Bytes
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