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/solve_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.
18 lines (14 sloc)
433 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 [x]=solve_tridiag(ud,uo,lo,b) | |
%Takes the main diagnol of the upper matrix and the off | |
%diagnol of the lower and upper matrices and the vector b. | |
%This function solves for the vector x. | |
y=zeros(1,length(ud)); | |
for i = 1:(length(ud)-1) | |
y(1)=b(1); | |
y(i+1)= b(i+1)-(lo(i)*y(i)); | |
end | |
x=zeros(1,length(ud)); | |
for k =(length(ud):-1:2) | |
x(length(ud))=y(length(ud))/ud(length(ud)); | |
x(k-1)= (y(k-1)-(uo(k-1)*x(k)))/(ud(k-1)); | |
end | |