%%%% Heat Diffusion in a Thin Insulated Wire, From Zhilin Li %%%%%% clear all; close all; L = 1.0; % Lenth of the Wire T = 150.; % Final Time n = 10; dx = L/n; % Number of Space Steps cond = .001; spheat = 1.0; rho = 1.; % material properties a = cond/(spheat*rho); % Simplify dt = dx*dx/(a*2.1); maxk=fix(T/dt); % Find the No. of steps b = dt/(dx*dx); d = a*b; % Initial Temperature for i = 1:n+1 x(i) =(i-1)*dx; u(i,1) =sin(pi*x(i)); end figure(1); plot(x,u'); axis([0 1 0 100]); pause(3) % Boundary Temperature for k=1:maxk+1 u(1,k) = 0.; u(n+1,k) = 0.; time(k) = (k-1)*dt; end % Time Loop for k=1:maxk % Space Loop for i=2:n; u(i,k+1) =1.*dt/(spheat*rho)+(1-2*d)*u(i,k) + d*(u(i-1,k)+u(i+1,k)); end figure(1); plot(x,u'); pause(2) end figure(2); mesh(x,time,u')