Init

Some Functions

(* general pure state in polar coordinates *)
State[θ_,ϕ_]:={Cos[θ/2],Sin[θ/2]Exp[I ϕ]}
(*normalized state with real first argument *)
StateNorm[x_List]:=Module[{arg1=Arg[x[[1]]],arg2=Arg[x[[2]]],normx=x/Norm[x],θ,ϕ},
θ=2Chop@ArcCos[normx[[1]]Exp[-I arg1]];
ϕ=Mod[arg2-arg1,2π];
{Cos[θ/2],Sin[θ/2]Exp[I ϕ]}]
(* outputs the polar coordinate from a state vector *)
blochcoord[state_]:=Module[{arg1=Arg[state[[1]]],arg2=Arg[state[[2]]],normx=state/Norm[state],θ,ϕ},
θ=Abs[2Chop@ArcCos[normx[[1]]Exp[-I arg1]]];
ϕ=Abs@Mod[arg2-arg1,2π];
{θ,ϕ}]
blochcoordcart[state_]:={Sin[#[[1]]]Cos[#[[2]]],Sin[#[[1]]]Sin[#[[2]]],Cos[#[[1]]]}&[blochcoord[state]]

(* define a bloch sphere graph *)
With[{r=1},xy=ParametricPlot3D[{r Cos[θ],r Sin[θ],0},{θ,0,2 π},PlotStyle->{Dashed,Opacity[0.3]},Boxed->False,Axes->False];
yz=ParametricPlot3D[{0,r Cos[θ],r Sin[θ]},{θ,0,2 π},PlotStyle->{Dashed,Opacity[0.3]},Boxed->False,Axes->False];
xz=ParametricPlot3D[{r Cos[θ],0,r Sin[θ]},{θ,0,2 π},PlotStyle->{Dashed,Opacity[0.3]},Boxed->False,Axes->False];
bloch=Show[Graphics3D[{Blue,Opacity[.15],Sphere[{0,0,0},r],Black,Opacity[1],Thick,Line[{{0,r,0},{0,-r,0}}],Line[{{0,0,r},{0,0,-r}}],Line[{{r,0,0},{-r,0,0}}],Text[Style["|1⟩",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,0,1.3 r}],Text[Style["|0⟩",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,0,-1.3 r}],Text[Style["|x+⟩",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{1.3 r,0,0}],Text[Style["|x-⟩",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{-1.3 r,0,0}],Text[Style["|y+⟩",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,1.3 r,0}],Text[Style["|y-⟩",FontSize->16,FontWeight->Bold,FontColor->GrayLevel[.3]],{0,-1.3 r,0}]}],xy,xz,yz,Boxed->False]];
(* generate vector for bloch sphere representation *)
Options[blochvec]={color->Blue};
blochvec[{θ_,ϕ_},OptionsPattern[]]:=Graphics3D[{OptionValue[color],Thickness[0.02],Line[{{0,0,0},{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]}}]}]
blocharrow[{θ_,ϕ_},opts:OptionsPattern[]]:=Arrow3D[{0,0,0},{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]},opts]

σx=(({{0, 1}, {1, 0}}));σy=(({{0, -I}, {I, 0}}));σz=(({{1, 0}, {0, -1}}));
(* draw vector for bloch sphere taking an arbitrary pure input state *)
blochvecstate[state_]:=blochvec@blochcoord[state]
blocharrowstate[state_,opts:OptionsPattern[]]:=blocharrow[blochcoord[state],opts]
(*bloch vector for mixed states *)
blochvecmsphere[r_,θ_,ϕ_]:=Graphics3D[{Blue,Thickness[0.02],Line[{{0,0,0},r{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]}}]}]
blochvecmsphere[{r_,θ_,ϕ_}]:=blochvec[r,θ,ϕ]
blochvecmarrowsphere[{r_,θ_,ϕ_},opts:OptionsPattern[]]:=Arrow3D[{0,0,0},r{Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]},opts]
(* cartesian coordinates *)
blochvecmcart[x_,y_,z_]:=Graphics3D[{Blue,Thickness[0.02],Line[{{0,0,0},{x,y,z}}]}]
blochvecmcart[{x_,y_,z_}]:=blochvecmcart[x,y,z]
blochvecmarrowcart[{x_,y_,z_},opts:OptionsPattern[]]:=Arrow3D[{0,0,0},{x,y,z},opts]
(* show vector with sphere *)
vectoronsphere[vec_]:=Show[bloch,vec,SphericalRegion->True]
(* Bloch-sphere coordinates from arbitrary state *)
MatrixToBloch[x_]:={Tr[σx.x],Tr[σy.x],Tr[σz.x]}

Urot[α_,t_,θ_,ϕ_]:=(({{Cos[α t/2] - I Cos[θ]Sin[α t /2], -I Exp[-I ϕ] Sin[θ] Sin[α t/2]}, {(-I Exp[I ϕ]) Sin[θ] Sin[α t/2], Cos[α t/2] + I Cos[θ]Sin[α t /2]}}))

RX[α_]:=Urot[α,1,π/2,0]
RY[α_]:=Urot[α,1,π/2,π/2]
RZ[α_]:=Urot[α,1,0,0]

SetOptions[ParametricPlot3D,PlotStyle->{Thick,Red},PlotRange->{{-1,1},{-1,1},{-1,1}},ImageSize->300,Axes->False,Boxed->False];
BlochSphere=Graphics3D[{Opacity[0.4],Sphere[{0,0,0},1]},Boxed->False];
BlochMesh=SphericalPlot3D[1,{θ,0,2 Pi},{ϕ,0,2Pi},MeshFunctions->{#4&},Mesh->{{Pi/2}},PlotStyle->Directive[Opacity[0]],Boxed->False,Axes->False];

Options[Arrow3D]={color->Red};
Arrow3D[a_,b_,OptionsPattern[]]:=Module[{l,n,rm,a3d,offset,col,arrowheadlength,thickness,arrowslope},
       col=OptionValue[color];
n=b-a;
l=Norm[n];
offset=l-1;
thickness=0.02;
arrowslope=0.3;
arrowheadlength=0.2;
rm=If[Abs[n]==l {0,0,1},Sign[n[[3]]]*IdentityMatrix[3],RotationMatrix[{{0,0,1},n}]];
a3d={ParametricPlot3D[rm.{(arrowslope v) Cos[u],(arrowslope v) Sin[u],1-v+offset},{u,0,2 π},{v,0,arrowheadlength},Mesh->None,PlotStyle->Directive[col]],ParametricPlot3D[rm.{v Cos[u],v Sin[u],1-arrowheadlength+offset},{u,0,2 π},{v,0,arrowslope*arrowheadlength},PlotStyle->Directive[col],Mesh->None],Graphics3D[{col,Cylinder[{a,b-arrowheadlength/l (b-a)},thickness]}]};
a3d];

Simple Pauli Operators and their effect on states :

σx ... Spinflip of basis state; more general: rotation by π about the x-axis

gs={0,1};
es={1,0};

σx.(({{0}, {1}}))//MatrixForm

vectoronsphere@blocharrowstate[gs]

vectoronsphere@blocharrowstate[σx.gs]

xpstate={(1/(Sqrt[2])),(1/(Sqrt[2]))};
σx.xpstate

{(1/(Sqrt[2])),(1/(Sqrt[2]))} is eigenvector to eigenvalue +1

vectoronsphere@blocharrowstate[xpstate]

vectoronsphere@blocharrowstate[σx.xpstate]

ypstate={(1/(Sqrt[2])),I(1/(Sqrt[2]))};

σx.ypstate

vectoronsphere@blocharrowstate[ypstate]

vectoronsphere@blocharrowstate[σx.ypstate]

σz ... Phaseflip of basis state; more general: rotation by π about the z-axis

σz//MatrixForm

vectoronsphere@blocharrowstate[es]

vectoronsphere@blocharrowstate[σz.es]

vectoronsphere@blocharrowstate[gs]

vectoronsphere@blocharrowstate[σz.gs]

factor -1 not visible on the Bloch sphere, since global phase is immaterial

superposition state on equatorial line is rotated about z-axis by an angle of π:

σz.xpstate

vectoronsphere@blocharrowstate[xpstate]

vectoronsphere@blocharrowstate[σz.xpstate]

σy ... Spin+Phaseflip

σy.{0,1}//TrigToExp

again, phaseflip is not visible on Blochsphere for ground/excited state, since global phase is immaterial

vectoronsphere@blocharrowstate[gs]

vectoronsphere@blocharrowstate[σy.gs]

on x + state:

vectoronsphere@blocharrowstate[xpstate]

vectoronsphere@blocharrowstate[σy.xpstate]

σy.ypstate

{(1/(Sqrt[2])),(i/(Sqrt[2]))} is eigenvector to eigenvalue +1

vectoronsphere@blocharrowstate[ypstate]

vectoronsphere@blocharrowstate[σy.ypstate]

Unitary Evolution of spin - 1/2 particle in magnetic field

B-field in z-direction

Hamilton Operator :

σz//MatrixForm

H[A_]:= -A σz

The unitary matrix can be calculated  by using MatrixExp:

Rz[A_,t_]:=MatrixExp[I A σz t]

Rz[(Subscript[μ, n])B0,t]//MatrixForm

start in the ground state :

Manipulate[
vectoronsphere@blochvecstate[Rz[1,t].gs],{t,0,2π}]

start in the |x +> state:

Manipulate[
vectoronsphere@blochvecstate[Rz[1,t].xpstate],{t,0,2π}]

B-field in x-direction

Hamilton Operator :

Hx[B_]:= -B σx

exponentiation:

Rx[B_,t_]:=MatrixExp[I Hx[B]t]

Rx[(Subscript[μ, n])B0,t]//MatrixForm

Manipulate[
vectoronsphere@blochvecstate[Rx[1,t].gs],{t,0,2π}]

B-field in y - direction :

-> Rotation about y axis instead of rotation about x - axis

Ry[C_,t_]:=MatrixExp[I C σy t];

Manipulate[
vectoronsphere@blochvecstate[Ry[1,t].gs],{t,0,2π}]

Manipulate[GraphicsRow[{
vectoronsphere@blochvecstate[Ry[1,t].gs],vectoronsphere@blochvecstate[Rx[1,t].gs]},ImageSize->700],{t,0,2π}]