1、设定N=100,a=3, b=40, T0=8, s=20x-4T Matlab源程序代码:length=2;N=100;iterN=0;eps=1.0e-4;deltQ=2;T2=(1:N);T2(1)=8;T2(N)=1;dx=length/(N-2);while (deltQ=eps & iterN50) T=T2;for i=1:N k(i)=3*T(i)3; sc(i)=20*(i-1)/N; sp(i)=4;endk(N/2+1:N)=40*T(N/2+1:N).3;for i=2:N-1 if i=2 a(i-1)=-2*k(i)/dx; c(i-1)=-2*k(i)*k(i+1
2、)/dx/(k(i)+k(i+1); b(i-1)=-a(i-1)-c(i-1)-sp(i)*dx; d(i-1)=sc(i)*dx-a(i-1)*T(i-1); else if i=N-1; a(i-1)=-2*k(i)*k(i-1)/dx/(k(i)+k(i-1); c(i-1)=-2*k(i+1)/dx; b(i-1)=-a(i-1)-c(i-1)-sp(i)*dx; d(i-1)=sc(i)*dx-c(i-1); else a(i-1)=-2*k(i)*k(i-1)/dx/(k(i)+k(i-1); c(i-1)=-2*k(i)*k(i+1)/dx/(k(i)+k(i+1); b(i-
3、1)=-a(i-1)-c(i-1)-sp(i)*dx; d(i-1)=sc(i-1)*dx; end endendif abs(b(1)=abs(c(1) | abs(b(N-2)=abs(c(N-2) warndla(,);endfor i=1:N-2 if abs(b(i)abs(c(i)+abs(a(i) warndla(,); endendfor i=1:N-2 if i=1 u(1)=b(1); else l(i)=a(i)/u(i-1); u(i)=b(i)-l(i)*c(i-1); endendfor i=1:N-2 if i=1 y(1)=d(1); else y(i)=d(i)-l(i)*y(i-1); endendfor j=N-2:-1:1 if j=N-2 x(N-2)=y(N-2)/u(N-2); else x(j)=(y(j)-c(j)*x(j+1)/u(j); endend iterN=iterN+1; T2(2:N-1)=x(1:N-2); deltQ=max(abs(T2-T);endfor i=1:10 Q(i,1:10)=T2(1+(i-1)*10):i*10);enddisp(Q);上面程序有乱码,附截图一份: