How to define an operator:

(Subscript[S, n_]):=D[#,{x,n}]&;

SS:=Sin[#]&

P:=-I ℏ (∂_x)#&

;

H:=((-(ℏ^2))/(2m))D[#[x],{x,2}]+V[x]#[x]&;

H@ψ==T ψ[x]//TraditionalForm

Using Operators on Harmonic Oscillator

;

V[x_]:=(1/2)m (ω^2) (x^2)

;

(SubPlus[a]):=(1/(Sqrt[2 ℏ ω m]))(((-I)/(ω m))P@#+x#)&;

(Subscript[a, n_]):=NestList[(SubPlus[a]),#,n][[n+1]]&;

(SubMinus[a]):=(1/(Sqrt[2 ℏ ω m]))((I/(ω m))P@#+x#)&;

(Subscript[b, n_]):=NestList[(SubMinus[a]),#,n][[n+1]]&;

;

;

DSolve[(SubMinus[a])@(ϕ[x])==0,ϕ[x],x][[1]][[1]]/.Rule->Equal//FullSimplify

η[x_]:=A (E^(-((m (x^2) ω)/(2 ℏ))))

Solve[Normal@(∫_(-∞)^∞)((( η[x]))^2)\[DifferentialD]x==1,A][[2]]

η[x_]:=((((((m ω)/ℏ)))^(1/4))/(π^(1/4)))* (E^(-((m (x^2) ω)/(2 ℏ))))

;

m=1;ℏ=1;ω=1;

Plot[{η[x]+.5,V[x]},{x,-5,5},PlotRange->{0,7},PlotStyle->{Blue,Red,{Black,Dashed}},PlotLabels->{(Subscript["η", 0]),"V(x)"}]

(SubPlus[a])@η[x]

Solve[Normal@(∫_(-∞)^∞)(A^2)((((SubPlus[a])@η[x]))^2)\[DifferentialD]x==1,A]

Plot[{(((Sqrt[2]) (E^(-((x^2)/2))) x)/(π^(1/4)))+1+.5,V[x]},{x,-5,5},PlotRange->{0,7},PlotStyle->{Blue,Red,{Black,Dashed}},PlotLabels->{(Subscript["η", 1]),"V(x)"}]

V[x_]:=(1/2)m (ω^2) (x^2)

A[n_]:=A/.Solve[Normal@(∫_(-∞)^∞)(A^2)((((Subscript[a, n])@η[x]))^2)\[DifferentialD]x==1,A][[2]][[1]]

Manipulate[Plot[{Evaluate[((Subscript[a, +n])@(A[n]η[x]))+(n+.5)*ℏ*ω],V[x],Table[(i+.5)*ℏ*ω,{i,0,5}]},{x,-5,5},PlotRange->{0,7},PlotStyle->{Blue,Red,{Black,Dashed}},PlotLabels->{(Subscript["η", n])(Subscript["E", n]),"V(x)"}],{n,0,5,1}]

Particle in a Box

k==(Sqrt[((2 m T)/(ℏ^2))]);

v[x_]:=0

ψ''[x]==-(k^2)ψ[x]//TraditionalForm

DSolve[{ψ''[x]==-(k^2)ψ[x],ψ[0]==0},ψ[x],x][[1]][[1]]/. Rule->Equal

Solve[A  Sin[k L]==0,k]

ξ[x_]:=A  Sin[((n π)/L) x]

Solve[Normal@(∫_0^L)(((ξ[x]))^2)\[DifferentialD]x==1,A]

Assuming[n∈Integers,Solve[Normal@(∫_0^L)(((ξ[x]))^2)\[DifferentialD]x==1,A]]

(Subscript[ξ, n_])[x_]:=({{\[Piecewise], ({{((Sqrt[2])/(Sqrt[L]))  Sin[((n π)/L) x], 0<=x<=L}, {0, x>L}, {0, x<0}})}})

;

Manipulate[Plot[Evaluate[(Subscript[ξ, n])[x]/.L->1],{x,-1,2},PlotRange->{{-1,2},{-2,5.5}},Epilog->{HalfLine[{1,0},{0,1}],HalfLine[{0,0},{0,1}]}],{n,1,10,1}]

k=((n π)/L)

Solve[k==(Sqrt[((2 m (Subscript[T, n]))/(ℏ^2))]),(Subscript[T, n])][[1]][[1]]/.Rule->Equal

Example 2.2 in The book:

ψ[x_,0]:=A x(L-x)

Solve[Normal@(∫_0^L)(((ψ[x,0]))^2)\[DifferentialD]x==1,A]

ψ:=((Sqrt[30])/(L^(5/2))) x (L-x)

;

$Assumptions =n ∈ Integers;

(Sqrt[(2/L)])(∫_0^L)Sin[((n π)/L)x] ψ\[DifferentialD]x//FullSimplify

(Subscript[C, n_]):=-((4 (Sqrt[15]) (-1+(((-1))^n)) )/((n^3) (π^3)))

;

(Subscript[C, 1])//Simplify

;

Ψ[x_,t_]:=({{\[Piecewise], ({{(∑_(n=1)^8)(Subscript[C, n])(Sqrt[(2/L)])Sin[((n π)/L)x] ComplexExpand[Re[Exp[((-I (n^2)(π^2)*(ℏ^2) t)/(2*m*(L^2)))]]]/.n->2n+1, 0<=x<=L}, {0, x>L}, {0, x<0}})}})

Manipulate[Plot[Ψ[x,t]/.L->1,{x,-1,2}],{t,0,10,AnimationRate->1}]