aUCBLogo Demos and Tests / blochequations
be blochequations
M=FloatArray {0 1 0}
dM_dt=FloatArray 3
B=FloatArray {0 1 0}
B0=1
B1=0
Mo=[]
gamma=1
M0=1
T1=100
T2=100
t=0
dt=0.01
omega=60
setUpdateGraph false
perspective
enableCylinderLines
black=RGB 0 0 0
size=350
forever
[ clearScreen
axes
repeat 5
[ B.1=B1*sin -omega*t
B.2=B0
B.3=B1*cos -omega*t
dM_dt.1=(gamma*(cross M B).1- M.1 /T2)
dM_dt.2=(gamma*(cross M B).2+(M0-M.2)/T1)
dM_dt.3=(gamma*(cross M B).3- M.3 /T2)
M=M+dM_dt*dt
t=t+dt
]
Mo=fPut M*size Mo
Home
setPosXYZ M*size
setPixel Mo black
PenUp
setXYZ 300 0 0
setHeading 90
PenDown
Label List omega Norm M
updateGraph
if Key?
[ ch=readChar
if ch==Char 27 [break]
if ch=="0 [B1=0]
if ch=="1 [B1=0.1]
if ch=="m [omega=omega*1.01]
if ch=="l [omega=omega/1.01]
]
]
end