% Heat Diffusion in a Thin Insulated Wire clear all; close all; L = 1.0; % Lenth of the Wire tfinal = 1; % Final Time n = 40.; dx = L/n; %Number of Space Steps rho = 1.; cond = 1/(pi*pi); spheat = 1.0; % Material parameters dt = dx*dx*rho*spheat/(cond*2.1); maxk = fix(tfinal/dt), % Number of Time Steps b = dt/(dx*dx); a = cond/(spheat*rho); d = a*b; % Initial Temperature for i = 1:n+1 x(i) = (i-1)*dx; u0(i) = sin(pi*x(i)); end plot(x,u0); hold t = 0; for k=1:maxk % Time Loop u1(1) = 0; u1(n+1) = 0; for i=2:n; % Space Loop u1(i) = 0.01*dt/(spheat*rho)+(1-2*d)*u0(i) + d*(u0(i-1)+u0(i+1)); end u0 = u1; plot(x,u1) t = t + dt; end for i=1:n+1 err(i) = u1(i)- uexact(x(i),t); end figure(2); plot(x,err) e2 = [norm(err,1),norm(err,2),norm(err,inf)],