Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. clear all
  2. close all
  3. lbox=50;
  4. vs=0.05;
  5. dt=1.;
  6. r=1.;
  7. rr=2;
  8. %random fluctuation
  9. eta = (2.*pi).*.1;
  10. nbird=300;
  11. nmolecules=600;
  12. birdl=[1:nbird];
  13. onebd=ones(1,nbird)';
  14. moll=[1:nmolecules];
  15. onem=ones(1,nmolecules)';
  16. figure
  17. axis([0 lbox 0 lbox])
  18. axis('square')
  19. hold on
  20. xb=rand(nbird,1).*lbox; %first possition
  21. yb=rand(nbird,1).*lbox; %first possition
  22. ang=pi.*2.*rand(nbird,1); %first oriantation
  23. xm=rand(nmolecules,1).*lbox; %first possition
  24. ym=rand(nmolecules,1).*lbox; %first possition
  25. vxb = vs.*cos(ang); %first velo
  26. vyb = vs.*sin(ang);
  27. vxm = 3.*rand(nmolecules,1);
  28. vym = 3.*rand(nmolecules,1);
  29. for nsteps=1:500;
  30. xb = xb + vxb.*dt;
  31. yb = yb + vyb.*dt;
  32. xm = xm + vxm.*dt;
  33. ym = ym + vym.*dt;
  34. for mol1 = 1:nmolecules;
  35. %periodic boundary condition
  36. if(xm(mol1)<0);xm(mol1)=xm(mol1)+lbox; end
  37. if (ym(mol1)<0);ym(mol1)=ym(mol1)+lbox;end
  38. if (xm(mol1)>lbox);xm(mol1)=xm(mol1)-lbox;end
  39. if (ym(mol1)>lbox);ym(mol1)=ym(mol1)-lbox;end
  40. %sep(1:nbird)=(onebd.*xb(bird1)-xb(1:nbird)).^2+ (onebd.*yb(bird1)- yb(1:nbird)).^2;
  41. %nearang=ang(sep<r);
  42. %mang(bird1)=mean(nearang);
  43. end
  44. for bird1 = 1:nbird;
  45. %periodic boundary condition
  46. if(xb(bird1)<0);xb(bird1)=xb(bird1)+lbox; end
  47. if (yb(bird1)<0);yb(bird1)=yb(bird1)+lbox;end
  48. if (xb(bird1)>lbox);xb(bird1)=xb(bird1)-lbox;end
  49. if (yb(bird1)>lbox);yb(bird1)=yb(bird1)-lbox;end
  50. sep(1:nbird)=(onebd.*xb(bird1)-xb(1:nbird)).^2+ (onebd.*yb(bird1)-yb(1:nbird)).^2;
  51. sepm(1:nmolecules)=(onem.*xb(bird1)-xm(1:nmolecules)).^2+ (onem.*yb(bird1)-ym(1:nmolecules)).^2;
  52. nearang=ang(sep<r);
  53. nearm=sepm<rr^2
  54. xmeanm=dot(nearm,xm)/(sum(nearm));
  55. ymeanm=dot(nearm,ym(1:nmolecules))/(sum(nearm));
  56. mang2(bird1)= atan(ymeanm/xmeanm);
  57. mang1(bird1)=mean(nearang);
  58. mang = (mang1(bird1)+ mang2(bird1) )/2;
  59. end
  60. ang=mang'+eta.*(rand(nbird,1)-0.5);
  61. vxb = vs.*cos(ang);
  62. vyb = vs.*sin(ang);
  63. vxm = 3.*(rand(nmolecules,1)-0.5);
  64. vym =3.*(rand(nmolecules,1)-0.5);
  65. cla
  66. set(gcf,'doublebuffer','on')
  67. plot(xb,yb,'.b')
  68. drawnow
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement