function [x y] = DiffusionMemPos(N,membrane,permeability,position) % N is a positive integer. % Simulates a 2D Diffusion with semipermeable membrane % x and y are row vectors with the property that (x(k),y(k)) is the % location of the token after N Time. %Membrane is where the molcules cannot cross %Permeability is the permeability of the membrane to that molecule %Position is whether it starts inside or out of the cell % Initializations... if (strcmp('In',position)) k = 0; xc = -10; yc = 0; else k=0; xc=10; yc=0; end % In general, (xc,yc) is the location after N time. % Boundary xMinBoundary=-20; xMaxBoundary=20; yMinBoundary=-20; yMaxBoundary=20; while kxMinBoundary+2) && (rand>permeability) %else if (xc>xMinBoundary+2) || (rand>permeability) xc = xc - 1; elseif (xcyMinBoundary+2 yc = yc - 1; else yc = yc +1; end end end % Save location... k = k + 1; x(k) = xc; y(k) = yc; end