%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sol=solve3diag(N, a, b, c, f)
%N is the number of unknowns, a,b,c are the three diagonals (from left to right), f is the right-hans side.  The routine returns the solution vector.
b1=b;
f1=f;
for i=2:N
	b1(i)=b(i)-a(i)*c(i-1)/b1(i-1);
	f1(i)=f(i)-a(i)*f1(i-1)/b1(i-1);
end;

sol(N)=f1(N)/b1(N);
for i=1:N-1
	sol(N-i)=(f1(N-i)-sol(N-i+1)*c(N-i))/b1(N-i);
end
