% m39_FisherKPP.m - explicit solution of Fisher-KPP equation % u_t = eps*u_xx + u - u^2, u(0)=1, u(10)=0 (nonlinear). % Grid and initial data: eps = 0.01; h = .05; k = .4*h^2/eps; % try .4 -> .51 x = (0+h:h:20-h)'; u = exp(-2*x) + (abs(x-3)<1); % initial data: wave front % Set-up for plot: hold off, shg, subplot(2,1,1) plt = plot(x,u,'linewidth',4); axis([0 20 -.01 1.1]), grid % Sparse matrix for finite difference operation: L = length(x); a = (1-2*k*eps/h^2); b = k*eps/h^2; bc = b*[1; zeros(L-1,1)]; main = a*sparse(ones(L,1)); off = b*sparse(ones(L-1,1)); A = diag(main) + diag(off,1) + diag(off,-1); % Time-stepping: disp('type to see solution') pause while 1 u = A*u + bc + k*(u-u.^2); % Euler's method set(plt,'ydata',u) drawnow end