n=6; t=20000; r=0.25; Ta=100; Tb=10; for i=1:(n-2) N0(i)=0; end N0(1)=r*Ta; N0(n-2)=r*Tb; for i=1:n-3 M(i,i)=1-2*r; M(i,i+1)=r; M(i+1,i)=r; end M(n-2,n-2)=1-2*r; u=zeros(n-2,1); for i=1:t u=M*u+N0'; end --------------------------------function y = tridiag( a, b, c, f ) n = length(f); v = zeros(n,1); y = v; w = a(1); y(1) = f(1)/w; for i=2:n v(i-1) = c(i-1)/w; w =a(i)-b(i)*v(i-1); y(i) = ( f(i) - b(i)*y(i-1) )/w; end for j=n-1:-1:1 y(j) = y(j) - v(j)*y(j+1); end -----------------------------f=zeros(9,1); f(1)=-100; f(9)=-10; y = tridiag(-2*ones(length(f),1),1*ones(length(f),1),1*ones(length(f),1),f)