Let us look at a problem we can solve exactly.
A particle of mass m moves in the potential energy function
U(x) = ∞, x < 0, x > a,
U(x) = 0, 0 < x < a.
The energy eigenfunctions are Φn(x) = (2/a)½sin(nπx/a)
with eigenvalues En =
n2π2ħ2/(2ma2), n = 1,
2, 3, ... .
k = 2π/λ = nπ/a, a = nλ/2.
∫0a k dx = (2π/λ) ∫0a dx = (2π/λ)(nλ/2)
= nπ for the eigenfunctions Φn(x).
∫0a (2/λ)dx = n, n counts the number of
half-wavelength or the number of anti-nodes of the wave function in the well.
If U(x) = finite when x < 0 or x > a, then the wave function does
not go to zero at the finite edge, but extends into the classically forbidden
region.
Therefore ∫0a (2/λ)dx = n - ε, where ε depends on the
exact nature of the edge(s).