Permalink
Cannot retrieve contributors at this time
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?
linear_algebra/lu_tridiag.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33 lines (26 sloc)
730 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ud, uo, lo ] = lu_tridiag( e,f,g ) | |
%This function takes 3 vectors as an input an computes the LU decomposition | |
%Function Input is 3 vectors: | |
%e - vector 1 subdiagonal vector | |
%f - vector 2 the diagonal vector | |
%g - vector 3 superidagonal vector | |
%Function outputs 3 vectors: | |
% ud - the upper diagonaland | |
% uo/ud - off diagonal for the lower and upper matricies | |
A=diag(e,-1)+ diag(f)+diag(g,1); | |
B=eye(length(f)); | |
for i=1:length(e) | |
x=A(i+1,i)/A(i,i); | |
A(i+1,i)= (-e(i)/f(i))*f(i)+e(i); | |
A(i+1,i+1)= (-x)*g(i)+f(i+1); | |
B(i+1,i)=x; | |
ud(1)=A(1,1); | |
ud(i+1)= A(i+1,i+1); | |
uo(i)=A(i,i+1); | |
lo(i)=B(i+1,i); | |
end | |
%this will display the function results | |
disp(ud) | |
disp(uo) | |
disp(lo) | |
end | |