-
Notifications
You must be signed in to change notification settings - Fork 4
/
TuringPDE.m
102 lines (94 loc) · 2.33 KB
/
TuringPDE.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function[x,X,Y,W,C]=TuringPDE(T,ns,plotting)
fprintf('Running Turing %d for %1.1f time units\n',ns,T)
if nargin<3
plotting=0;
end
k1=2;k2=0.2;k3=0.01;k4=0.08;k5=0.04;k6=3.37;k7=2;nc=6;DX=1;DY=0.04;
%T=1000;
X0=2.3069;
Y0=2;
W0=46.4039;
C0=1.3730;
%dx=0.05;L=6;
dx=0.1;L=12;
dt=0.05*dx^2/DX;
s=0.01;
x=0:dx:L;
n=length(x);
X=X0*ones(n)+s*rand(n,n);
Y=Y0*ones(n)+s*rand(n,n);
W=W0*ones(n)+s*rand(n,n);
C=C0*ones(n)+s*rand(n,n);
t=0;
i=0;
if plotting
ts = [];
Xmin = [];
Xmax = [];
fh = figure;
fh.Position = [200 300 1000 400];
end
while t<T
d2X=4*del2(X,dx);
d2Y=4*del2(Y,dx);
switch ns
case 4
dX=dt*(-k1*X.*Y-2*k3*X.^2+k4+k7*(nc-C)+DX*d2X);
dY=dt*(-k1*X.*Y+2*k2*W-k5*Y-k6*Y.*C+DY*d2Y);
dW=dt*(k1*X.*Y-k2*W+k3*X.^2);
dC=dt*(-k6*Y.*C+k7*(nc-C));
X=X+dX;
Y=Y+dY;
W=W+dW;
C=C+dC;
X(1,:)=X(2,:);X(n,:)=X(n-1,:);X(:,1)=X(:,2);X(:,n)=X(:,n-1);
Y(1,:)=Y(2,:);Y(n,:)=Y(n-1,:);Y(:,1)=Y(:,2);Y(:,n)=Y(:,n-1);
W(1,:)=W(2,:);W(n,:)=W(n-1,:);W(:,1)=W(:,2);W(:,n)=W(:,n-1);
C(1,:)=C(2,:);C(n,:)=C(n-1,:);C(:,1)=C(:,2);C(:,n)=C(:,n-1);
case 3
dX=dt*(-k1*X.*Y-2*k3*X.^2+k4+k6*k7*nc*Y./(k7+k6*Y)+DX*d2X);
dY=dt*(-k1*X.*Y+2*k2*W-k5*Y-k6*k7*nc*Y./(k7+k6*Y)+DY*d2Y);
dW=dt*(k1*X.*Y-k2*W+k3*X.^2);
X=X+dX;
Y=Y+dY;
W=W+dW;
X(1,:)=X(2,:);X(n,:)=X(n-1,:);X(:,1)=X(:,2);X(:,n)=X(:,n-1);
Y(1,:)=Y(2,:);Y(n,:)=Y(n-1,:);Y(:,1)=Y(:,2);Y(:,n)=Y(:,n-1);
W(1,:)=W(2,:);W(n,:)=W(n-1,:);W(:,1)=W(:,2);W(:,n)=W(:,n-1);
case 2
dX=dt*(-k1*X.*Y-2*k3*X.^2+k4+k6*k7*nc*Y./(k7+k6*Y)+DX*d2X);
dY=dt*(k1*X.*Y+2*k3*X.^2-k5*Y-k6*k7*nc*Y./(k7+k6*Y)+DY*d2Y);
X=X+dX;
Y=Y+dY;
X(1,:)=X(2,:);X(n,:)=X(n-1,:);X(:,1)=X(:,2);X(:,n)=X(:,n-1);
Y(1,:)=Y(2,:);Y(n,:)=Y(n-1,:);Y(:,1)=Y(:,2);Y(:,n)=Y(:,n-1);
end
t=t+dt;
i=i+1;
if plotting
if mod(i,1000)==0
%t/T
subplot(1,2,1)
surf(x,x,X);
set(gca,'layer','top','tickdir','out')
shading flat
grid off
view([0 90])
%imagesc(X)
colorbar
title(sprintf('t = %1.3f',t))
drawnow;
ts = [ts t];
Xmin = [Xmin min(min(X))];
Xmax = [Xmax max(max(X))];
subplot(1,2,2)
plot(ts,Xmax-Xmin)
ylabel('max(X) - min(X)')
end
else
if mod(i,1000)==0
fprintf('.')
end
end
end
end