MATLAB.8 Partial Differential Equations Solving the Heat Equation . Let f(x)=0 if 00 u(0,t)=u(2,t)=0 t>0, u(x,0)=f(x) . The Fourier sine coefficients for f are b(m)=(cos(m*pi/2)-cos(m*pi))*2/m/pi The M-file computing the first n terms is ***************************************************************** function w=U(x,t,n) w=0; for m=1:n w=w+2*(cos(m*pi/2)-cos(m*pi))/m/pi*exp(-m^2*pi^2*t/4).*sin(m*pi*x/2); end *************************************************************** Notice the .* above. We will do a 3-dimensional plot and U.m needs to be array smart for this. Let's set n=50. To plot the temperature distribution at different times enter ***************************************************************** hold on fplot('U(x,0,50)',[0,2]) fplot('U(x,.1,50)',[0,2]) fplot('U(x,.5,50)',[0,2]) fplot('U(x,1,50)',[0,2]) fplot('U(x,2,50)',[0,2]) fplot('U(x,5,50)',[0,2]) hold off ************************************************************* To do a 3-D plot on the x-t rectangle 00 u(0,t)=u(40,t)=0 t>0, u(x,0)=x for 00 u(0,t)=u(10,t)=0 t>0, u(x,0)=1 for 4