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

main - grad B drift

main - grad B drift

GradBdrift.m — Objective-C source code, 869 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 ; % here we have spatial variation
By = 0.0 ;
Ex = 0.0 ; % no electric field just B gradient
Ey = 0.0 ;
Ez = 0.0 ;

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

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

tfin = 50 
time = 0:0.01:tfin;
[x_sol,t] = lsode("gradBfunc",[x0 ;y0; z0; u0; v0; w0],time); % solve equation of motion *** Octave ***
% [t,x_sol] = ode23(@gradBfunc,[0 tfin],[x0 ;y0; z0; u0; v0; w0]) % use this for *** Matlab ****
figure(1)
plot3(x_sol(:,1),x_sol(:,2),x_sol(:,3),'r');
xlabel('x')
ylabel('y')
zlabel('z')
title('Grad B drift')
figure(2)
plot(time,x_sol(:,5),'b',time,mean(x_sol(:,5))*ones(length(time),1),'r');
xlabel('time')
legend('v','mean(v)')