Matlab program for reaction diffusion system

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 6K views
yaboidjaf
Messages
5
Reaction score
0
I'm trying to model a reaction-diffusion system on MATLAB and am struggling.
I'm starting off with 4 particles on a lattice with 15 sites for ease, will take it to a larger scale when I've got the simple version down. the idea is to get randomly walking particles to eventually meet each other and annihiilate.

here's my program

%% getting annihilation to work for 4 particles on 15 lattice sites
clear all
array = round(15*rand(1,4)) % 2 particle system on 10 lattice sites
jump = rand(1,4) % generate 2 random numbers, one for each particle
for x = 1:4
if jump(x) <= 0.5 %if the corresponding number is less than 0.5, the particle moves left, else right.
array(x) = array(x) - 1;
else
array(x) = array(x) + 1;
end
end

so i have the particles all conducting random walks (not sure if it's the best way), but I'm not sure how to go about identifying whether two particles are on the same lattice point and how to go about getting them to annihilate. i have a feeling the way my walks are set up it would be difficult to do so.
 
Physics news on Phys.org
It might be easier to create a class that will represent the particles. The class can have a particle-identity and walk method. Another method could be used to test if particles are on the same site.