You are here: Home Education Computational Plasma Physics main- ExB drift

main- ExB drift

main- ExB drift

EcrossBdrift.m — Objective-C source code, 825 bytes

File contents

close all;
clear all;

global Bx; global By; global Bz;
global Ex; global Ey; global Ez;
global qom; 

% charge to mass ratio
qom = 1
% EM fields
Bz = 1.0 ; % B in z direction
Bx = 0.0 ;
By = 0.0 ;
Ex = 0.2 ; % E in x direction
Ey = 0.0 ;
Ez = 0.0 ;

% initial position
x0 = 0; 
y0 = 0; 
z0 = 0;

% initial velocity
u0 = 0.5;
v0 = 0.0;
w0 = 0.0;

tfin = 50 % in s
time = 0:0.01:tfin;
[x_sol,t] = lsode("ExBfunc",[x0 ;y0; z0; u0; v0; w0],time); % solve equation of motion *** Octave ***
% [t,x_sol] = ode23(@ExBfunc,[0 tfin],[x0 ;y0; z0; u0; v0; w0]) % use this for *** Matlab ****
figure(1)
plot(x_sol(:,1),x_sol(:,2),'r'); % plot trajectory in x y plane
xlabel('x')
ylabel('y')
title('E x B drift')
figure(2)
plot(time,x_sol(:,5),'b',time,mean(x_sol(:,5))*ones(length(time),1),'r');
xlabel('time')
legend('u','mean(u)')