Guest User

Untitled

a guest
Apr 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. function meinhardtg6( nScenario)
  2.  
  3. %meinhardt: Simulate Meinhardt's (2001) n-th scenario.
  4. %----------------------------------------------------------
  5. % Here I have implemented Meinhardt's equations exactly as
  6. % he shows them in his Basic program, in order to get you
  7. % started on your project. However there are several things
  8. % you must do, which I haven't done here:
  9. % 1. Meinhardt's simulation is 1-D - you need 2-D.
  10. % 2. This uses Euler integration of the DE's - you need RK.
  11. % 3. Meinhan extremelrdt uses ay long time-step dt=1. You
  12. % may well need a much smaller one, which will make
  13. % your simulation slower.
  14. % 4. Meinhardt uses Fixed boundary conditions - I have used
  15. % Periodic boundary conditions. You may use either
  16. % Periodic, Fixed or Zero-flux boundary conditions to
  17. % achieve your target pattern. (See Miura & Maini (2004)
  18. % for an explanation of these boundary conditions).
  19. % 5. You will also need to match your pattern against a
  20. % target pattern, and you will perform this comparison
  21. % by using a Fourier classification of both your
  22. % generated pattern and your target pattern.
  23. % 6. Beware of ill-conditioning! You should be able to
  24. % recognise it when it occurs, and hopefully using the
  25. % RK method should help, but if not, you will need to
  26. % reduce the length of your time-step to restore
  27. % well-conditioned behaviour.
  28. %----------------------------------------------------------
  29. if nargin < 1
  30. nScenario = 1; % Periodic pattern
  31. end;
  32.  
  33. % Set up scenario constants:
  34. switch nScenario
  35. case 1
  36. % Periodic pattern:
  37. Tmax = 70000; Xmax = 80; % Max t and x value
  38. dt = .1; dx = 1; % Step-sizes
  39. au = 0.010; av = 0.061; % Decay constants
  40. bu = 0.1; bv = 0; % Base expression rates
  41. Du = 0.01; Dv = 0.3; % Diffusion constants
  42. otherwise
  43. disp( 'Sorry: unknown scenario!');
  44. return;
  45. end;
  46.  
  47. % Define the domain:
  48. Nt = floor(Tmax/dt) + 1;
  49. Nx = floor(Xmax/dx) + 1;
  50. T = dt*(0:(Nt-1));
  51. X = dx*(0:(Nx-1));
  52.  
  53.  
  54. % Set up slightly noisy initial conditions:
  55. noise = 0.005;
  56. lu = au*(1 + noise*(2*rand(Nx,Nx)-1));
  57. u = ones(Nx,Nx);
  58. v = u;
  59.  
  60. % Reaction rules:
  61. f = @(u,v) lu.*(u.^2 + bu)./(v) - au*u;
  62. g = @(u,v) lu.*u.^2 - av*v + bv;
  63.  
  64.  
  65. % Display initial state:
  66. figure(1);
  67. pcoloru = pcolor(X,X,u);
  68. %pcoloru = surf(u);
  69. shading interp;
  70. colormap('jet');
  71. figure(2);
  72. pcolorv = pcolor(X,X,v);
  73. %pcolorv = surf(v);
  74. shading interp;
  75. colormap('jet');
  76. drawnow;
  77.  
  78.  
  79.  
  80. % u(round(Nx/2),round(Nx/2)) = 100;
  81. % %v((round(Nx/2)+15),round(Nx/2)) = 10000;
  82. % v(1:(round(Nx/2)),round(Nx/2)) = 1000;
  83.  
  84.  
  85.  
  86.  
  87. % Simulation loop:
  88. for t = 1:Nt-1
  89.  
  90. u(round(Nx/2),round(Nx/2)) = 1;
  91. v(1:(round(Nx/2)),round(Nx/2)) = 5;
  92. u = u + dt * (f(u,v) + Du*coolshift2(u,dx));
  93. %v(round(5*end/1):round(6*end/11),end) = 20000;
  94. v = v + dt * (g(u,v) + Dv*coolshift2(v,dx));
  95. %v(1:(round(Nx/2)),round(Nx/2)) = 50;
  96. %v((end),end) = 20000;
  97. % v(round(4*end/9):round(5*end/9),end) = 2000;
  98.  
  99. if mod(t,500) == 0
  100. t
  101. % plot(X,u,X,v);
  102. set(pcoloru,'CData',u); % update with new data u
  103. set(pcolorv,'CData',v); % update with new data v
  104. drawnow; % This is necessary if we want animation
  105. end
  106.  
  107.  
  108. % plot(X,u,'b', X,v,'r');
  109. % surf(u);
  110. % shading flat;
  111. % if (mod(t,250) == 0)
  112. % drawnow; % This is necessary if we want animation
  113. % end
Add Comment
Please, Sign In to add comment