Problem plotting the trajectory of electron in static electromagnetic field

28 views (last 30 days)
I. Content :
When the electron moves in an uniform electromagnetic field, it will be acted by Lorentz force:
We can thus determine the acceleration of the electron. If we know the initial position and velocity, we can determine the kinetic motion equations of electron . Eliminating t from mentioned motion equations, we can derive , which is the orbital equation of electron.
II.Task :
Write Matlab program to:
  1. Input the initial position (), velocity of the electron (); constant static electric () and magnetic field () parallel to z-axis.
  2. Use symbolic operations to calculate the electromagnetic force acting on the electron, thereby deriving the electron's acceleration, velocity, and motion equation.
  3. Plot the trajectory of the electron
IIT.My take on this :
EXPECTED OUTPUT:
Expected OUTPUT
MY OUTPUT:
MY
MY CODE:
function pjoject6_alpha
clc
clear
syms t vx(t) vy(t) vz(t) x(t) y(t) z(t) C
%[INPUT] FOR INITIAL POSITION: x0 y0 z0
xyz = [0 0 0];
x0= xyz(1);
y0= xyz(2);
z0= xyz(3);
%[INPUT] FOR INITIAL VELOCITY VECTOR
v0 = [1.75 1 1];
v0x= v0(1);
v0y= v0(2);
v0z= v0(3);
%[INPUT] FOR
% E : ELECTRIC FIELD VECTOR
% B : MAGNETIC FIEL VECTOR
E = [0 0 1.5];
B = [0 0 1];
%[PREDEFINED CONSTANT]
% me : MASS OF ELECTRON
% q : PARTICLE CHARGE OF ELECTRON
me= 9.10938*10^-31; q= -1.60276*10^-19;
%[CACULATING] ACCELERATION VECTOR
% USING F = me.accel = q.(E) + q.(v.B)
accel = (E + cross(v0, B))*q/me; % cross(v0,B) : multiply vector v0 with vector B
%[SOLVE] FOR VELOCITY EQUATION vx(t), vy(t), vz(t)
vx = dsolve([diff(vx(t),t) == accel(1),vx(0) == v0x]);
vy = dsolve([diff(vy(t),t) == accel(2),vy(0) == v0y]);
vz = dsolve([diff(vz(t),t) == accel(3),vz(0) == v0z]);
x= dsolve([diff(x) == vx, x(0) == x0 ]);
y= dsolve([diff(y) == vy, y(0) == y0 ]);
z= dsolve([diff(z) == vx, z(0) == z0 ]);
if vz== 0
fplot(x, y); title('Trajectory ');
else
fplot3(x, y, z); title('Trajectory ');
end
end
MY THOUGHT PROCESS:
Followed the instruction, I reckon that I need to find the Vector of acceleration (accel).
After that I dsolve them to get the equation for velocity , respectively
I do the same for another time and get .
The last step is to fplot3(x,y,z) (The plot function will eliminate t and return an equation for the relation of
MY SPECULATION REGARDING THE ERROR:
I think there was something wrong with the plotting.
When I tried to eliminate t manually using eliminate():
equa = [x;y;z]
sol = eliminate(equa,t)
disp(sol)
output:
sol =
Empty sym: 1-by-0
And I think this is why i got a straight line
Please help me, I'm a complete novice

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 11 Oct 2022
When you let the symbolic solver handle your equations of motion it might be safer to simply give dsolve the second-order equation straight-off and see if that handles it all in one go. Also it might be very good if you sit down an solve these equations by hand first. They separate nicely into two equations perpendicular to B and one || to B. That at least gives you some understanding of the problem.
syms m_e q_e positive % remember that q_e now is the positive elementary charge
syms E [3,1] real
syms B [3,1] real
syms t
syms r(t) [3,1]
D2rDt2 = diff(r,2)
syms r0 [3,1] real
syms v0 [3,1] real
DrDt = diff(r);
qwe = dsolve(D2rDt2 == -q_e/m_e*(E + cross(DrDt,B)),r(0)==r0,Dr(0) == v0);
% Check those general solutions and appreciate the power of orienting your
% coordinates!
qwe.r1
qwe.r2
qwe.r3
%% A slightly more sensible setup:
syms Bz real
syms Ex Ez real
asd = dsolve(D2rDt2 == -q_e/m_e*([Ex;0;Ez] + cross(DrDt,[0;0;Bz])),r(0)==r0,Dr(0) == v0);
% this solution you will have to look into more carefully, preferably with
% pen and paper, or with repeated use of the simplify and expand functions.
Then for plotting I strongly suggest you don't bother "eliminating t", simply calculate the electron-gyro-frequency and the gyro-period, and plot the trajectories for a couple of gyro-periods (5-8 or something in that range).
HTH
  11 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 19 Oct 2022
Good!
(If someone tasks you with solving the equations of motion for charged particles in E and B-fields have a look at the Boris-mover, it is a way better integration-method for these eq-s of motion than the standard ODE-solvers. The wikipedia-entry is sufficient.)

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!