
function [phi] = tdma(a,b,c,d,phi,ni)

nim1=ni-1;
p(1)= 0;
q(1)=phi(1);
for i=2:nim1                                              

%            calculate coefficients of recurrence formula                      
   term= (a(i)-c(i)*p(i-1));                                        
   if abs(term)<1.e-10
      term=1.e-10;
   end  
   p(i)= b(i)/term;
   q(i)= (d(i)+c(i)*q(i-1))/term; 
end
%         obtain new phi@s                                       
for ii=2:nim1                                  
    i= ni+1-ii;                                          
    phi(i)= p(i)*phi(i+1)+q(i);
end
