% numerics for problem 3 x = -5:0.01:5; psi = (exp(-(x-1).^2) + i*exp(-(x+1).^2))/sqrt(2); area = trapz(x,abs(psi).^2); C2 = 1/sqrt(area); psi = C2*psi; % now psi is normalized expvalx = trapz(x,conj(psi).*x.*psi); expvalx2 = trapz(x,conj(psi).*(x.^2).*psi); % There is a really small imaginary part, % in my code of order 10^-20; however, here % we take the real part. expvalx = real(expvalx); expvalx2 = real(expvalx2); dx = x(2) - x(1); dpsidx = diff(psi)/dx; % These are at the midpoint values because the derivatives are % evaluated at the midpoints. psimid = 0.5*(psi(1:(length(psi) -1)) + psi(2:length(psi))); xmid = 0.5*(x(1:(length(psi) -1)) + x(2:length(psi))); expvalp = -i*trapz(xmid,conj(psimid).*dpsidx); % with hbar = 1 % Again the imaginary part is very small. expvalp = real(expvalp); N = length(x); d2psidx2 = diff(dpsidx)/dx; x = x(2:(N-1)); psi = psi(2:(N-1)); expvalp2 = - trapz(x,conj(psi).*d2psidx2); % with hbar = 1 % The imaginary part is much smaller than the real part. expvalp2 = real(expvalp2); Deltax = sqrt(expvalx2 - expvalx^2); Deltap = sqrt(expvalp2 - expvalp^2); Deltax*Deltap % This number should be greater or equal to 1/2, which it is.