% This is the Computer Exercise 3, Section 7.3 Tridiagonal and banded systems,
% from Cheney and Kincaid
% Example use:
% d = [1;2;3;4;5];
% b = [2;4;6;8;10];
% [x]=Tri_Ex3(d,b)
function [x] = Tri_Ex3(d,b)
dorig=d;
borig=b;
n = length(d);

for i = 2:n
    xmult = 1/d(i-1);
    d(i)=d(i) - xmult;
    b(i) = b(i) - xmult*b(i-1);
end

x(n)=b(n)/d(n);
for i=n-1:-1:1
    x(i) = (b(i)- x(i+1))/d(i);
end
fprintf('The solution is\n')
x
a=ones(1,n-1);
c=ones(1,n-1);
y=Tri(a,dorig,c,borig);
fprintf('The solution using "Tri" function is\n')
y
end
