Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
| 5. |
Code View:
Scroll
/
Show All BeginPackage ["HarmonicOscillator'"] HarmonicOscillator: : usage = "HarmonicOscillator' is a package that provides functions for the eigenenergies and normalized energy eigenfunctions of the simple harmonic oscillator." φ: : usage = "φ[n, x] gives the normalized energy eigenfunctions of the simple harmonic oscillator." ε: : usage = "ε[n] gives the eigenenergies of the simple harmonic oscillator in terms of ћω." ω: : usage = "The symbol ω stands for the oscillator frequency." m: : usage = "The symbol m stands for the mass." ћ: : usage= "The symbol ћ stands for h/2π with h being Planck's counstant." Begin ["'Private'"] HarmonicOscillator: :badarg= "You called '1' with '2' argument (s) ! It must have '3' argument (s)." φ: :quannum = "The quantum number must be a nonnegative integer. your quantum number '1' is not allowed." ε: :badarg = "The argument must be a nonnegative integer. You entered '1'." φ[n_Integer? NonNegative, x_]: = ((2^ (–/2)) (n ! ^ (–1/2)) (((mω) / (ћπ)) ^ (1/4)) HermiteH [n, Sqrt [mω/ћ]x]Exp [– ((mω) / (2ћ))x^2]} φ[n_, x_] : = Message [φ: :quannum, {n}] φ [arg _ _ _ / ; Length [{arg]] ≠ 2] : = Message [HarmonicOscillator: :badarg, φ, Length [{arg}], 2] ε[n_Integer ? NonNegative] : = ћω (n + 1/2)) ε[arg_]: = Message [ε: :badarg, {arg}] ε[arg_ _ _/ ; (Length [{arg}] ≠1)] : = Message [HarmonicOscillator: :badarg, ε, Length [{arg}], 1] End[] Protect [φ, ε] EndPackage[] |