(* This notebook is related to Exercise 4 problem 5. To be more precise, the ground state energy and the binding energy are calculated below. *)

(* Let us clear variables. *)
Clear[e,m, ℏ,a,V]

(* Let us define ξ and R. We have added the factor (1.602*10^(-19)) after energy e in order to obtain the ground state energy in electron volts. *)
ξ=Sqrt[2m*(e*(1.602*10^(-19)))/(ℏ^2)]a
R=Sqrt[2m*V/(ℏ^2)]a

(* Let us set the values of electron mass m, reduced Planck constant ℏ, the one-half width of the well a and the well depth V. The physical unit of each quantity is its SI unit. *)
m=9.109*10^(-31)
ℏ=1.055*10^(-34)
a=0.5*10^(-10)
V=3.204*10^(-19)

(* Let us define variables lhs and rhs to be the left-hand side and right-hand side of Eq. (5.2). *)
lhs=ξ^2(Tan[ξ])^2
rhs=R^2-ξ^2

(* Let us use the FindRoot command to determine a root for Eq. (5.2). *)
FindRoot[lhs==rhs, {e,0}]

(* We remember that this is in terms of electron volts. *)

(* Let us plot the variables lhs and rhs in order to check whether our root is the smallest root. *)
Plot[{lhs,rhs},  {e, 0, 2.2}, PlotStyle->{{Hue[0.0]},{Hue[0.6]}}]

(* This corroborates our result for the ground state energy. Furthermore, we see the ground state is actually the only bound state. *)

(* Let us now calculate the binding energy (cf. Eq. (5.1)). *)
2-1.77604