% d2alg.m
clear all
dx=.1;a=5;x=-a:dx:a; n=length(x);f=exp(-x.^2)';
D2=diag(ones([n-1,1]),-1)-2*diag(ones([n,1]),0)+diag(ones([n-1],1),1);D2=D2/dx^2;
ddf=D2*f;ddfe=(4*x.^2-2)'.*exp(-x.^2');
plot(x,ddfe),hold on,plot(x,ddf,'o') 