%例1:有限长细杆的热传导的定解问题x=0:20; t=0:0.01:1; a2=10;r=a2*0.01;u=zeros(21,101);u(10:11,1)=1;for j=1:100u(2:20,j+1)=(1-2*r)*u(2:20,j)+r*( u(1:19,j)+ u(3:21,j);plot(u(:,j); axis(0 21 0 1); pause(0.1)endmeshz(u)%例2:非齐次方程的定解问题的解析解a2=50;b=5;L=1;x,t=meshgrid(0:0.01:1,0:0.000001:0.0005); Anfun=inline(2/L*(x-L/2).2.*exp(-b*x./2/a2).*sin(n*pi*x/L),x,n,L,b,a2); %定义内联函数u=0;for n=1:30 An=quad(Anfun,0,1,n,L,b,a2); %inline函数中定义x为向量,其它为标量 un=An*exp(-(