Writing code for Boundary (membrane) for osmosis
    3 views (last 30 days)
  
       Show older comments
    
Can anyone help me with this assignment question:
In this assignment you will adapt your computer model of brownian motion to mimic Osmosis – the diffusion of two molecular species in the presence of a semi-permeable membrane. 
• Model the effect of a membrane placed at x=-2, one of the molecule types can diffuse through the membrane, the second is reflected by it 
• You will need to think about what happens to Dx and Dy upon reflection 
This is the code I've written but unsure how to set up boundary conditions to refelct one of the particles. Thank you for any help! 
clear;
clc;
nsteps = 100; % Number of steps
np= 300; % Number of Particles
np2=300; %Number of second set particles 
% Initialization of the position of particles
x = zeros(1,np);
y = zeros(1,np);
% Particles randomly moving 
for j=1:np 
for i = 1:nsteps
    theta = 2*pi*rand();
    r = 1; % distance of each step 
    dx = r*cos(theta);
    dy = r*sin(theta);
    x(i+1,j)=x(i,j)+dx;
    y(i+1,j)=y(i,j)+dy;
end
x2 = zeros(1,np);
y2 = zeros(1,np);
for a=1:np2   
for b = 1:nsteps
    theta = 2*pi*rand();
    r = 1; 
    dx = r*cos(theta);
    dy = r*sin(theta);
    x2(b+1,a)=x2(b,a)+dx;
    y2(b+1,a)=y2(b,a)+dy;  
    end 
end
end
figure(1)
for k=1:np
scatter(x(:,k),y(:,k));
hold on 
scatter(x2(:,k),y2(:,k),'+');drawnow 
pause(3)
hold off 
end
0 Comments
Answers (0)
See Also
Categories
				Find more on Deep Learning Toolbox in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!