Contents[hide]
YouTube
Simulation [gnuplot]
Modeling
Lorentz force \begin{equation} \label{eq:lorentz} m\boldsymbol{\ddot{x}} = \color{red}{q\boldsymbol{E}} + \color{blue}{q (\boldsymbol{v}\times \boldsymbol{B})} \end{equation}
Assume \boldsymbol{E}=\left(-kx, -ky, 2kz\right)\ \left(k\ge 0\right), \boldsymbol{B}=\left(0, 0, B\right), q=-e.Then from (\ref{eq:lorentz})
\begin{eqnarray}
\ddot{x} &=& \frac{e}{m}\left(kx-\dot{y}B\right) \label{eq:x} \\
\ddot{y} &=& \frac{e}{m}\left(ky+\dot{x}B\right) \label{eq:y} \\
\ddot{z} &=& -\frac{2ek}{m}z \label{eq:z}
\end{eqnarray}
em_motion_gif.plt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setting ---------------------------------------- | |
reset | |
set term gif animate delay 5 size 1280,720 | |
set output "em_motion.gif" | |
set margins 0, 0, 0, 0 | |
unset key | |
unset grid | |
set xl "x" font"Times:Italic, 22" | |
set yl "y" font"Times:Italic, 22" | |
# Parameter ---------------------------------------- | |
m = 2.0 # [kg] | |
e = 0.1 # [C] | |
k = 15 # [N/Cm] | |
B = 65 # [N/Am] | |
b = e*B/(2*m) | |
R1 = 10 # Large radius [m] | |
R2 = 30 # Small radius [m] | |
omg0 = sqrt(e*k/m) # Angular velocity of z | |
omg1 = b + sqrt(b**2-omg0**2) | |
omg2 = b - sqrt(b**2-omg0**2) | |
r = 0.8 # Radius of the ball | |
dt = 0.001 # step | |
dh = dt/6.0 | |
dec = 50 # Decimation | |
mag = 0.15 | |
limit = 30/dt # loop limit | |
DATA = "motion_data_gif.dat" | |
set print DATA | |
# Functions ---------------------------------------- | |
# Lorentz force | |
f1(x, y, z, vx, vy, vz) = vx # dx/dt | |
f2(x, y, z, vx, vy, vz) = vy # dy/dt | |
f3(x, y, z, vx, vy, vz) = vz # dz/dt | |
f4(x, y, z, vx, vy, vz) = e/m*(k*x-vy*B) # dvx/dt | |
f5(x, y, z, vx, vy, vz) = e/m*(k*y+vx*B) # dvy/dt | |
f6(x, y, z, vx, vy, vz) = -2*e*k*z # dvz/dt | |
# Runge-Kutta 4th (Define rk_i(x, y, z, vx, vy, vz)) | |
do for[i=1:6]{ | |
rki = "rk" | |
fi = "f".sprintf("%d", i) | |
rki = rki.sprintf("%d(x, y, z, vx, vy, vz) = (\ | |
k1 = %s(x, y, z, vx, vy, vz),\ | |
k2 = %s(x + dt*k1/2., y + dt*k1/2., z + dt*k1/2., vx + dt*k1/2., vy + dt*k1/2., vz + dt*k1/2.),\ | |
k3 = %s(x + dt*k2/2., y + dt*k2/2., z + dt*k2/2., vx + dt*k2/2., vy + dt*k2/2., vz + dt*k2/2.),\ | |
k4 = %s(x + dt*k3, y + dt*k3, z + dt*k3, vx + dt*k3, vy + dt*k3, vz + dt*k3),\ | |
dh * (k1 + 2*k2 + 2*k3 + k4))", i, fi, fi, fi, fi) | |
eval rki | |
} | |
# Time | |
Time(t) = sprintf("{/Times:Italic t} = %3.1f s", t) | |
# Plot ---------------------------------------- | |
# Initial Value | |
t = 0 | |
x = R1 + R2 | |
y = 0 | |
z = 20 | |
vx = 0 | |
vy = R1*omg1+R2*omg2 | |
vz = 0 | |
print x, y, z, vx, vy, vz # Write initial value into DAT file | |
# Draw initiate state for 70 steps | |
do for [i = 1:70] { | |
set label 1 Time(t) at screen 0.5, 0.90 font 'Times:Normal, 20' | |
set multiplot | |
# xyz-space | |
set view 60, 30, 1, 1.2 | |
set origin 0.020,0.03 | |
set size 0.60, 0.60*1280/720 | |
set zl "z" font"Times:Italic, 22" | |
set xyplane at -50 | |
# Lorentz force | |
set arrow 1 from x, y, z to x+mag*e*k*x, y+mag*e*k*y, z-mag*2*e*k*z front lc rgb'red' lw 2 | |
set arrow 2 from x, y, z to x-mag*e*B*vy, y+mag*e*B*vx, z-mag*2*e*k*z front lc rgb 'blue' lw 2 | |
# Ball | |
set obj 1 circ at x, y, z size r fc rgb 'black' fs solid front | |
set obj 2 circ at x, y, -40 size r fc rgb 'black' fs solid front | |
splot[-50:50][-50:50][-50:50] DATA using 1:2:3 with line linecolor rgb "black" lw 1 | |
# xy-plane | |
set pm3d map | |
set origin 0.55,0.11 | |
set size 0.48, 0.48*1280/720 | |
unset zl | |
# Gray circles | |
set obj 3 circ at 0, 0 size R2-R1 fc rgb 'gray50' fs transparent noborder behind | |
set obj 4 circ at 0, 0 size R2 fc rgb 'gray50' fs transparent noborder behind | |
set obj 5 circ at 0, 0 size R2+R1 fc rgb 'gray50' fs transparent noborder behind | |
splot[-50:50][-50:50][-50:50] DATA using 1:2:3 with line linecolor rgb "black" lw 1 | |
unset multiplot | |
do for[j=3:5]{ | |
unset obj j # In order not to show obj 3,4,5 in xyz-space | |
} | |
} | |
# Update for limit steps | |
do for [i = 1:limit] { | |
t = t + dt | |
x = x + rk1(x, y, z, vx, vy, vz) | |
y = y + rk2(x, y, z, vx, vy, vz) | |
z = z + rk3(x, y, z, vx, vy, vz) | |
vx = vx + rk4(x, y, z, vx, vy, vz) | |
vy = vy + rk5(x, y, z, vx, vy, vz) | |
vz = vz + rk6(x, y, z, vx, vy, vz) | |
print x, y, z, vx, vy, vz # Write the values into DAT file | |
if(i%dec==0){ | |
# Update time | |
set label 1 Time(t) at screen 0.5, 0.93 font 'Times:Normal, 20' | |
set multiplot | |
# xyz-space | |
set view 60, 30, 1, 1.2 | |
set origin 0.020,0.03 | |
set size 0.60, 0.60*1280/720 | |
set zl "z" font"Times:Italic, 22" | |
set xyplane at -50 | |
# Lorentz force | |
set arrow 1 from x, y, z to x+mag*e*k*x, y+mag*e*k*y, z-mag*2*e*k*z front lc rgb'red' lw 2 | |
set arrow 2 from x, y, z to x-mag*e*B*vy, y+mag*e*B*vx, z-mag*2*e*k*z front lc rgb 'blue' lw 2 | |
# Ball | |
set obj 1 circ at x, y, z size r fc rgb 'black' fs solid front | |
set obj 2 circ at x, y, -50 size r fc rgb 'black' fs solid front | |
splot[-50:50][-50:50][-50:50] \ | |
DATA using 1:2:3 with line linecolor rgb "black" lw 1, \ | |
DATA using 1:2:(-50) with line linecolor rgb "black" lw 1 | |
# xy-plane | |
set pm3d map | |
set origin 0.55,0.11 | |
set size 0.48, 0.48*1280/720 | |
unset zl | |
# Gray circles | |
set obj 3 circ at 0, 0 size R2-R1 fc rgb 'gray50' fs transparent noborder behind | |
set obj 4 circ at 0, 0 size R2 fc rgb 'gray50' fs transparent noborder behind | |
set obj 5 circ at 0, 0 size R2+R1 fc rgb 'gray50' fs transparent noborder behind | |
splot[-50:50][-50:50][-50:50] \ | |
DATA using 1:2:3 with line linecolor rgb "black" lw 1 | |
unset multiplot | |
do for[j=3:5]{ | |
unset obj j # In order not to show obj 3,4,5 in xyz-space | |
} | |
} | |
} | |
set out |
em_motion.gif
Extra
Analytical solution
Solving (\ref{eq:z}), we obtein \begin{equation} z=C\cos\left(\sqrt{2}\omega_{0}t+\alpha\right), \end{equation}
where
{\omega_{0}}^2=\frac{ek}{m}.
Rearranging (\ref{eq:x}) and (\ref{eq:y}), we have
\begin{eqnarray}
\left\{ \label{eq:xy}
\begin{array}{l}
\ddot{x}-{\omega_{0}}^2 x+2b\dot y=0\\
\ddot{y}-{\omega_{0}}^2 y+2b\dot x=0,
\end{array}
\right.
\end{eqnarray}
where
b=\frac{eB}{2m}
By putting x=Ae^{i\omega t} and y=Be^{i\omega t}, substitution of these in (\ref{eq:xy}) leads to (\ref{eq:xy2}).
\begin{eqnarray}
\left\{ \label{eq:xy2}
\begin{array}{l}
-\left(\omega^2+{\omega_{0}}^{2}\right)A+2ib\omega B = 0 \\
-2ib\omega A-\left(\omega^2+{\omega_{0}}^{2}\right)B = 0.
\end{array}
\right.
\end{eqnarray}
To get the solutions except for A=B=0, solve (\ref{eq:det}):
\begin{equation}
\left|
\begin{array}{cc}
-\left(\omega^2+{\omega_{0}}^{2}\right) & 2ib\omega \\
-2ib\omega & -\left(\omega^2+{\omega_{0}}^{2}\right)
\end{array}
\right| = 0 \label{eq:det}
\end{equation}
\therefore\omega^2+{\omega_0}^2 = \pm 2b\omega \label{eq:det2}
When b is greater than \omega_0, we obtain
\begin{eqnarray}
\label{eq:omega}
\left\{
\begin{array}{l}
\pm\omega_1 = b+\sqrt{b^2-{\omega_0}^2} \\
\pm\omega_2 = b-\sqrt{b^2-{\omega_0}^2}.
\end{array}
\right.
\end{eqnarray}
Inserting (\ref{eq:omega}) into (\ref{eq:xy2}), we get
\begin{eqnarray}
\frac{B}{A} =
\begin{cases}
-i && (+\omega_1, +\omega_2)\\
i && (-\omega_1, -\omega_2).
\end{cases}
\end{eqnarray}
\begin{eqnarray}
\label{eq:solution}
\therefore\left\{
\begin{array}{l}
x = A_1 e^{i\omega_1 t}+A_2 e^{-i\omega_1 t}+A_3 e^{i\omega_2 t}+A_4 e^{-i\omega_2 t} \\
y = -i A_1 e^{i\omega_1 t}+i A_2 e^{-i\omega_1 t}-i A_3 e^{i\omega_2 t}+i A_4 e^{-i\omega_2 t} \\
\end{array}
\right.
\end{eqnarray}
We put
\begin{eqnarray}
\label{eq:Ralpha}
\begin{cases}
R_1 = 2\sqrt{A_1 A_2} \\
R_2 = 2\sqrt{A_3 A_4} \\
\alpha_1 = \tan^{-1}\left[\frac{i\left(A_1-A_2\right)}{A_1+A_2}\right]\\
\alpha_2 = \tan^{-1}\left[\frac{i\left(A_3-A_4\right)}{A_3+A_4}\right].
\end{cases}
\end{eqnarray}
Combining (\ref{eq:solution}) and (\ref{eq:Ralpha}), we obtain
\begin{eqnarray}
\left\{
\begin{array}{l}
x = R_1 \cos\left(\omega_1 t+\alpha_1\right)+R_2 \cos\left(\omega_2 t+\alpha_2\right) \\
y = R_1 \sin\left(\omega_1 t+\alpha_1\right)+R_2 \sin\left(\omega_2 t+\alpha_2\right).
\end{array}
\right.
\end{eqnarray}
EM_field.plt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setting ---------------------------------------- | |
reset | |
set term png size 1280, 720 | |
set margins 0, 0, 0, 0 | |
unset key | |
unset grid | |
set xl "x" font"Times:Italic, 22" | |
set yl "y" font"Times:Italic, 22" | |
# Parameter ---------------------------------------- | |
m = 2.0 # [kg] | |
e = 0.1 # [C] | |
k = 15 # [N/Cm] | |
B = 65 # [N/Am] | |
b = e*B/(2*m) | |
R1 = 10 # Large [m] | |
R2 = 30 # Small [m] | |
omg0 = sqrt(e*k/m) | |
omg1 = b + sqrt(b**2-omg0**2) | |
omg2 = b - sqrt(b**2-omg0**2) | |
mag = 0.15 | |
array Name[2] = ["E_field", "B_field"] | |
array Color[2] = ["red", "blue"] | |
array File[2] = [".dat", ".png"] | |
# Functions ---------------------------------------- | |
# Electric field | |
Ex(x, y, z) = -k*x | |
Ey(x, y, z) = -k*y | |
Ez(x, y, z) = 2*k*z | |
# Magnetic field | |
Bx(x, y, z) = 0 | |
By(x, y, z) = 0 | |
Bz(x, y, z) = B | |
# Plot ---------------------------------------- | |
inc = 8 # increment | |
do for [f=1:2]{ | |
if(f==1){ # Electric field | |
k = 15 | |
B = 0 | |
mag = 0.005 | |
} else { # Magnetic field | |
k = 0 | |
B = 65 | |
mag = 0.08 | |
} | |
set print Name[f].File[1] | |
do for [x=-40:40:inc] { | |
do for[y=-40:40:inc] { | |
do for[z=-40:40:inc]{ | |
vx = mag*((f==1)?Ex(x, y, z):Bx(x, y, z)) | |
vy = mag*((f==1)?Ey(x, y, z):By(x, y, z)) | |
vz = mag*((f==1)?Ez(x, y, z):Bz(x, y, z)) | |
print x, y, z, vx, vy, vz | |
} | |
} | |
} | |
set output Name[f].File[2] | |
set multiplot | |
# xyz-space | |
set view 60, 30, 1, 1.2 | |
set origin 0.020,0.03 | |
set size 0.60, 0.60*1280/720 | |
set zl "z" font"Times:Italic, 22" | |
set xyplane at -50 | |
splot[-50:50][-50:50][-50:50] \ | |
Name[f].File[1] using 1:2:3:4:5:6 w vec lc rgb Color[f] lw 1 | |
# xy-plane | |
set pm3d map | |
set origin 0.55,0.11 | |
set size 0.48, 0.48*1280/720 | |
unset zl | |
splot[-50:50][-50:50][-50:50] \ | |
Name[f].File[1] using 1:2:3:4:5:6 w vec lc rgb Color[f] lw 1 | |
unset multiplot | |
} | |
set out |