Zadanie 1 (dla n=4)

vL[x_,b_,c_]:=x^2+b x+c
vR[x_]:=x^4+4x-4
u[x_,b_,c_]:=vL[x,b,c]HeavisideTheta[-x]+vR[x]HeavisideTheta[x]

Solve[{vL[0,b,c]==vR[0],(D[vL[x,b,c],x]/.x->0)==(D[vR[x],x]/.x->0)},{b,c}]

Plot[u[x,4,-4],{x,-6,2}]

v[x_]:=u[x,4,-4]

FindMinimum[v[x],{x,2*^-6}]

xmin=-2;
ϕ[i_,x_]:=1/Sqrt[2^i i!Sqrt[π]]HermiteH[i,x-xmin]Exp[-(x-xmin)^2/2]

Hij[i_,j_]:=NIntegrate[ϕ[i,x](-1/2D[ϕ[j,x],{x,2}]+v[x]ϕ[j,x]),{x,-∞,∞}]

K=20;
matH=Table[Hij[i,j],{i,0,K},{j,0,K}];

{ee,ev}=Eigensystem[matH]//Transpose//Sort//Transpose;

ee

vec=Table[ϕ[i,x],{i,0,K}];

Psi[i_,x_]:=ev[[i]].vec

Plot[{Psi[1,x]+ee[[1]],Psi[2,x]+ee[[2]],v[x]},{x,-5,1.6},PlotRange->All]

Zadanie 2 (n=9)

vv[x_]:=1/2x^2+5Exp[-9 x^2]
Plot[vv[x],{x,-4,4},PlotRange->Automatic]

ger[ener_,start_,end_]:=NDSolve[{-1/2χ''[x]+vv[x]χ[x]==ener χ[x],χ[0]==1,χ'[0]==0},χ,{x,start,end}]

r1g=ger[1.389221275,-15,15]
r2g=ger[3.2242803317,-15,15]
r3g=ger[5.059339159,-15,15]
Plot[{χ[x]/.r1g,χ[x]/.r2g,χ[x]/.r3g},{x,-6,6}]

x2sr1g=NIntegrate[x^2(χ[x]/.r1g)^2,{x,-6,6}]/NIntegrate[(χ[x]/.r1g)^2,{x,-6,6}]

ung[ener_,start_,end_]:=NDSolve[{-1/2χ''[x]+vv[x]χ[x]==ener χ[x],χ[0]==0,χ'[0]==1},χ,{x,start,end}]

r1u=ung[1.6255074570,-12,12]
r2u=ung[3.66277044389,-12,12]
r3u=ung[5.6775562689,-12,12]
Plot[{χ[x]/.r1u,χ[x]/.r2u,χ[x]/.r3u},{x,-7,7}]

x2sr1u=NIntegrate[x^2(χ[x]/.r1u)^2,{x,-6,6}]/NIntegrate[(χ[x]/.r1u)^2,{x,-6,6}]

Normalizacja funkcji

n1g=1/Sqrt[NIntegrate[(χ[x]/.r1g)^2,{x,-6,6}]]
n2g=1/Sqrt[NIntegrate[(χ[x]/.r2g)^2,{x,-6,6}]]
n3g=1/Sqrt[NIntegrate[(χ[x]/.r3g)^2,{x,-6,6}]]

Plot[{n1g*(χ[x]/.r1g),n2g*(χ[x]/.r2g),n3g*(χ[x]/.r3g)},{x,-6,6},PlotStyle->{Black,{Black,Dashed},{Black,Dotted}},PlotLegends->{"(Subscript[ψ, 1  g])","(Subscript[ψ, 2  g])","(Subscript[ψ, 3  g])"},ImageSize->Large,Frame->True]

n1u=1/Sqrt[NIntegrate[(χ[x]/.r1u)^2,{x,-6,6}]]
n2u=1/Sqrt[NIntegrate[(χ[x]/.r2u)^2,{x,-6,6}]]
n3u=1/Sqrt[NIntegrate[(χ[x]/.r3u)^2,{x,-6,6}]]

Plot[{n1u*(χ[x]/.r1u),n2u*(χ[x]/.r2u),n3u*(χ[x]/.r3u)},{x,-6,6},PlotStyle->{Gray,{Gray,Dashed},{Gray,Dotted}},PlotLegends->{"(Subscript[ψ, 1  u])","(Subscript[ψ, 2  u])","(Subscript[ψ, 3  u])"},ImageSize->Large,Frame->True]