clear all; close all; % Grid: N = 2^8; L = 10; x2 = linspace(-L/2,L/2,N+1); x = x2(1:N); dx = x(2) - x(1); % Diffusion parameter: kappa = .5; % Time span for solution: tspan = [0:1:10]; % Create sparse D2 matrix: e1 = ones(N,1); A = spdiags([e1 -2*e1 e1],[-1 0 1],N,N); A(1,N) = 1; A(N,1) = 1; % Create initial condition: U0 = exp(-x.^2); % Call ODE solver: [t,U] = ode45('heat_1d_rhs',tspan,U0,[],kappa,dx,A);