You are here: Home Education Computational Plasma Physics helper function to calculate grad B

helper function to calculate grad B

helper function to calculate grad B

getBmod.m — Objective-C source code, 208 bytes

File contents

function B_mod = getBmod(x,y,z)
global B0;  global Re; 
fac1 =  -B0*Re^3/(x^2 + y^2 + z^2)^2.5;
Bx = 3*x*z*fac1;
By = 3*y*z*fac1;
Bz = (2*z^2 -x^2- y^2)*fac1;
B_mod = sqrt(Bx*Bx + By*By + Bz*Bz);
endfunction