Issues modelling particle spin
Mostrar comentarios más antiguos
Hello, I've been working on my code to simulate particles diffusing in a 1D box in the presence of a magnetic field gradient. The gradient is in one dimension but increases in strength as a function of position in the box.
The issue arises with the summing of the spins, they should all theoretically become out of phase and sum to 0, but they usually generate large numbers. Can anyone see any issues with the code or, even worse, my physics!
Code:
clear all
h = 1000000;
T = 1*10^-6;
ts = 10^-7;
D = 0.282;
ga = (267.513 * 10^6)*360/(2*pi);
xsi=(2*D*ts)^0.5;
W = xsi*25;
B0 = 0.00001;
G = 20;
t = ts;
m = 1;
omg = pi*ones(1,h);
n = zeros(1,h);
rot = zeros(1,h);
r = ones(1,h);
k = 1;
bins = (-W:xsi:W);
while sum(rot) >= 0;
x = round(rand(1,h));
for m = 1 : h;
if n(m) >= W - xsi
n(m) = n(m) - xsi;
elseif n(m) <= - W + xsi
n (m) = n(m) + xsi;
else
if x(m) == 1
n(m) = n(m) + xsi;
elseif x(m) == 0
n(m) = n(m) - xsi;
end
end
omg(m) = ga*(G*n(m)+B0)*ts;
rot(m) = rot(m) + omg(m);
end
t = t + ts;
k = k + 1;
end
sum(rot)
Respuestas (0)
Categorías
Más información sobre Neuroimaging en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!