From: Max Carlson on
Basically what I need to do is code a tridiagonal solver and be able to implement it with sparse matrices. Right now I feel my code is a bit off and I am not sure what I need to tweak. So far I have:

function x = project2(a,b,c,d,n)
for i = 2:n
s= -a(i-1)/b(i-1);
b(i)= b(i)+c(i-1)*s;
d(i)= d(i)+b(i-1)*s;
end
x(n)=d(n)/b(n);
for i = n-1:-1:1
x(i)= (b(i)-c(i)*x(i+1))/b(i)
end

Keep in mind I am pretty new to Matlab and new to programming in general, so any help I can get would be greatly appreciated. Thanks.