(*  Mecanica Quantica serie 9 *)

A={{0,1,0,0,0,0},
   {0,0,Sqrt[2],0,0,0},
   {0,0,0,Sqrt[3],0,0},
   {0,0,0,0,Sqrt[4],0},
   {0,0,0,0,0,Sqrt[5]},
   {0,0,0,0,0,0}}

AP=Transpose[A]
H=hbar w DiagonalMatrix[{1/2,3/2,5/2,7/2,9/2,11/2}]
x= Sqrt[hbar/(2 m w)] ( A + AP)
p= -I Sqrt[hbar  m w /2] ( A - AP)
u0={1,0,0,0,0,0}
psi=1/Sqrt[6] {1,2,1,0,0,0};


AP2= AP . AP;
AP3=AP2 . AP;
AP4=AP3 . AP;
u1=1/Sqrt[1] AP . u0;
u2=1/Sqrt[2!] AP2 . u0;
u3=1/Sqrt[3!] AP3 . u0;
u4=1/Sqrt[4!] AP4 . u0;
Hmed = psi . H . psi;
xmed = Simplify[ psi . x . psi];
x2med = Simplify[psi . x . x . psi];
pmed = Simplify[ psi . p . psi];
p2med = Simplify[ psi . p . p . psi];
dx2 = Simplify[x2med-xmed^2];
dp2 = Simplify[p2med-pmed^2];
heisenberg=Simplify[Sqrt[dx2 dp2],Assumptions->hbar>0];
heisenbergN=N[heisenberg];
