% This problem is similar to leftside.m except that the wavefunction % is centered about 0.5 with width Delta on each side of 0.5. nterms = 100; % Number of terms kept in the series. Delta = 0.1; n = 1:nterms; c = 2*sin(0.5*n*pi).*sin(n*pi*Delta)./(pi*n)/sqrt(Delta); x = 0:0.001:1; psi = 0*x; for counter = 1:nterms, psi = psi + c(counter)*sqrt(2)*sin(pi*counter*x); end psi2exact = (x > (0.5 - Delta)).*(x < (0.5 + Delta))/(2*Delta); plot(x,psi.^2,x,psi2exact) xlabel('x') ylabel('|psi|^2')