You are here: Home Education Computational Plasma Physics function- trajectory in magnetic dipole

function- trajectory in magnetic dipole

function- trajectory in magnetic dipole

Newton_Lorenz.m — Objective-C source code, 903 bytes

File contents

function x_res   = Newton_Lorenz(x_vect,t)  % use this definition in *** Octave ***
% function x_res = Newton_Lorenz(t, x_vect) % use this in *** Matlab ***

% x_vect(1) = x
% x_vect(2) = y
% x_vect(3) = z
% x_vect(4) = u
% x_vect(5) = v
% x_vect(6) = w

global B0; global q; global m; global Re; 
x_res = zeros(6,1);


% calculate 3 Cartesian components of the magnetic field
fac1 =  -B0*Re^3/(x_vect(1)^2 + x_vect(2)^2 + x_vect(3)^2)^2.5;
Bx = 3*x_vect(1)*x_vect(3)*fac1;
By = 3*x_vect(2)*x_vect(3)*fac1;
Bz = (2*x_vect(3)^2 -x_vect(1)^2- x_vect(2)^2)*fac1;

qom = q/m;
x_res(1) = x_vect(4); % dx/dt = u
x_res(2) = x_vect(5); % dy/dt = v
x_res(3) = x_vect(6); % dz/dt = w
x_res(4) = qom*(x_vect(5)*Bz - x_vect(6)*By); % du/dt = qom*(vel x B)_x
x_res(5) = qom*(x_vect(6)*Bx - x_vect(4)*Bz); % dv/dt = qom*(vel x B)_y
x_res(6) = qom*(x_vect(4)*By - x_vect(5)*Bx); % dw/dt = qom*(vel x B)_z


endfunction