clear, close all %show time decay of solution to heat equation u0 = @(x) exp(x).*sin(7*pi*x).*cos(pi*x); f = @(x,N) 2*u0(x).*sin((1:N)*pi*x); fouriersol = @(xx, a, T) (sin((1:length(a)).*xx*pi).*exp(-((1:length(a))*pi).^2*T))*a.'; xx = linspace(0,1)'; Nref = 30; aref = integral(@(x) f(x, Nref), 0, 1, 'ArrayValued',true); for t = (0:0.001:0.01)+0.01 plot(xx, fouriersol(xx, aref, t)); hold on pause end