The following code represents obtaining the commutator of the square of the angular momentum vector and the down-ladder operator both associated with the H-atom electronic energy level quantum mechanics. It is a simple example of using the non-commutative algebra parts of Maxima to do computations.
reset() + kill(all);
dotscrules:true$
Lxsq:Lx.Lx$
Lysq: Ly.Ly$
Lzsq: Lz.Lz$
Lsq: Lxsq+Lysq+Lzsq$
Aminus:(Ax-%i*Ay);
AminusLsq : Aminus.Lsq$
LsqAminus : Lsq.Aminus$
print ("expanded initial form")$
comm:(AminusLsq-LsqAminus),expand;
comm: substitute(Lx.Lx.Ax =Lx.Ax.Lx,comm)$
comm: substitute(Ly.Ly.Ay =Ly.Ay.Ly,comm)$
comm: substitute(Lz.Lz.Az =Lz.Az.Lz,comm)$
comm: substitute(Ax.Lx.Lx =Lx.Ax.Lx,comm)$
comm: substitute(Ay.Ly.Ly =Ly.Ay.Ly,comm)$
print ("expanded after i,i exchanged form")$
comm: substitute(Az.Lz.Lz =Lz.Az.Lz,comm);
/*AyLz−LzAy=i hbarAx*/
print("1 z-y LzAyLz" )$
comm: substitute(%i*Lz.(Lz.Ay) =%i*(Lz.(Ay.Lz)-%i*%hbar*Lz.Ax),comm),expand;
comm: substitute(%i*Ay.(Lz^^2) =%i*(Lz.(Ay.Lz)+%i*%hbar*Ax.Lz),comm),expand;
/*AyLx−LxAy=−i hbarAz*/
print ("2 x-y *Lx(Lx.Ay) ")$
comm: substitute(Lx.Lx.Ay =(Lx.(Ay.Lx)+%i*%hbar*Lx.Az),comm),expand;
comm: substitute(%i*Ay.Lx^^2 =%i*(Lx.Ay.Lx-%i*%hbar*Az.Lx),comm),expand;
/*AxLy−LyAx=i hbarAz*/
print ("3 x-y *Ly(Ly.Ax) ")$
comm:substitute(Ax.Ly^^2=Ly.Ax.Ly+%i*%hbar*Az.Ly,comm),expand;
comm:substitute((Ly^^2).Ax=Ly.Ax.Ly-%i*%hbar*Ly.Az,comm),expand;
/*AxLz−LzAx=−i hbarAy*/
print("4 x-z Lz.(Lz.Ax) : ")$
comm: substitute(((Lz^^2).Ax) =Lz.(Ax.Lz)+%i*%hbar*Lz.Ay,comm),expand;
comm: substitute((Ax.Lz^^2) =Lz.Ax.Lz-%i*%hbar*Ay.Lz,comm),expand;
comm:comm/%hbar$
comm:expand(comm);
tex(%);
Sunday, October 4, 2020
maxima using SageMath
This article deals with using Maxima under CoCalc (earlier SageMath).
The reason for this usage is that wxMaxima does not print properly, and I needed to print some incorrect code to find my error(s) in peace and quiet. Using the starting line "%maxima", which tells SageMath that the following code is to be passed to Maxima, one gets an immediate error with code which is longer than about 20 lines.
Sage Help (Stein) acknowledges that there is a programming error in Sage causing this problem, He suggested a work-around, which is used below. With the workaround, there still are several pitfalls. Comments are not accepted, blank lines fail also. No spaces, no comments, no $ terminators, only ;. Further, the maxima command tex(); fails.
In spite of the problems, it is worth passing this information along until wxMaxima maintainers fix the printing bug.
Here is an example of how to structure your Maxima code for SageMath(CoCalc):
def maxima2(s):
print(maxima.eval(s, allow_use_file=False))
%maxima2
dotscrules:true;
Lxsq:Lx.Lx;
Lysq: Ly.Ly;
Lzsq: Lz.Lz;
Lsq: Lxsq+Lysq+Lzsq;
Lminus : Lx - %i*Ly;
Aminus:(Ax-%i*Ay);
AminusLsq : Aminus.Lsq;
etc..
The reason for this usage is that wxMaxima does not print properly, and I needed to print some incorrect code to find my error(s) in peace and quiet. Using the starting line "%maxima", which tells SageMath that the following code is to be passed to Maxima, one gets an immediate error with code which is longer than about 20 lines.
Sage Help (Stein) acknowledges that there is a programming error in Sage causing this problem, He suggested a work-around, which is used below. With the workaround, there still are several pitfalls. Comments are not accepted, blank lines fail also. No spaces, no comments, no $ terminators, only ;. Further, the maxima command tex(); fails.
In spite of the problems, it is worth passing this information along until wxMaxima maintainers fix the printing bug.
Here is an example of how to structure your Maxima code for SageMath(CoCalc):
def maxima2(s):
print(maxima.eval(s, allow_use_file=False))
%maxima2
dotscrules:true;
Lxsq:Lx.Lx;
Lysq: Ly.Ly;
Lzsq: Lz.Lz;
Lsq: Lxsq+Lysq+Lzsq;
Lminus : Lx - %i*Ly;
Aminus:(Ax-%i*Ay);
AminusLsq : Aminus.Lsq;
etc..
Subscribe to:
Posts (Atom)